.NET Core unit testing code coverage
This sample solution includes a class library that is unit tested by two xUnit test projects. The corresponding article, use code coverage for unit testing details the usage of C#, xUnit, coverlet, and ReportGenerator.
Sample prerequisites
This sample is written in C# and targets .NET 6.0. It requires the .NET 6.0 SDK.
Building the sample
The source code includes an MSBuild project file for C# (a .csproj file) that targets .NET 6.0. Create a directory and select Download ZIP to download the example code files to your computer. To build the example:
- Download the .zip file containing the example code files.
- Create the directory to which you want to copy the files.
- Copy the files from the .zip file to the directory you just created.
- If you are using Visual Studio 2022:
- In Visual Studio, select Open a project or solution (or File > Open > Project/Solution from the Visual Studio menu.
- Select Debug > Build Solution from the Visual Studio menu to build the solution.
- If you are working from the command line:
- Navigate to the directory that contains the sample.
- Type in the command
dotnet build
to build the solution.