unlocking-the-power-of-software-testing-in-asp-net-enhancing-software-quality-x-unit-and-coverlet-i
Unlocking the Power of Software Testing in ASP.NET: Enhancing Software Quality: xUnit & Coverlet — I

Unlocking the Power of Software Testing in ASP.NET: Enhancing Software Quality: xUnit & Coverlet — I

Software tests are crucial to guarantee the delivery of a good quality product, indentify bugs, additionally offer comfort in the maintenance phase, code refactoring or even when changing team members, in addition to other benefits listed in part 1. As mentioned in the part 1, we will create a project with its corresponding test project using xUnit and Coverlet. To bring the example to life, we will create a folder for the projects. Within the folder, we will have a class library and the test project. Code to be tested In the class library below, we will have a class that contains a method that takes a string as input and validates whether it is a number and if it has no more than 10 characters. Commands to create the class library project. Test with xUnit Next, we have the test project that uses xUnit, and upon creation, it already includes the Coverlet library. To confirm this, after creating the test project, if we open the file xUnitCoverletTest.csproj, we will find one of the PackageReference entries as coverlet.collector. The test class validates the result of the method execution. In our example, if the method receives a string with only numbers and no more than 10 characters, it should return true, otherwise, the result is false. Two approaches were used for testing, one that allows passing multiple inputs as parameters to test ([Theory]) and another without parameters ([Fact]). The test project must reference our class library to be able to test the methods available in the class library. The following command allows referencing the class library. To confirm if it’s correct, you can open the file xUnitCoverletTest.csproj and check if there is a ProjectReference tag.

Share