Milan  Reilly

Milan Reilly

1626663148

Implement Unit Testing in ASP.NET Core 5 Application

This article will get you started with unit testing in the ASP.NET core application. We will start with creating an ASP.NET Core based application with math operation service and implement xUnit.net to automate testing of the operations available in this service.

As far as code to be tested is concerned I am keeping our goal simple here that is we will implement automated tests for a Math service, as this is our first article in the series and also so that in this article we can concentrate more on the concepts of unit testing i.e. xUnit.net.

What are Automated Unit Tests?

There is a need to test every software system before we deliver or deploy it to production to ensure the good quality of the product being delivered. Quality means not only it is defect-free but it also meets the user requirements.

Unit Tests is testing which involves rigorous testing of each small independent unit or component in isolation. There shouldn’t be a need to deploy or host a system to perform unit testing. Unit testing is to ensure that all independent small units of a larger software system are performing (in isolations) as per requirements.

Small independent units or components means these test should focus on a single component and should be as small as possible. i.e. don’t test multiple pieces things together instead test one piece at a time. i.e. if you are testing the controller then just focus on testing the controller code and do not test all the services which are being injected into the controller.

Automated unit tests are the automation of these unit test i.e. instead of performing unit test manually it is executed by some testing tool or framework.

This automation initially requires time for the development of these tests but at a later stage when code size grows it can considerably save time in performing unit testing over manual testing.

Automated unit testing in ASP.NET Core is supported by using third-party frameworks

#aspdotnet core #aspdotnet core 5

Implement Unit Testing in ASP.NET Core 5 Application