A sample repository for .NET 8 or later demonstrating code coverage with xUnit v3 and the Microsoft Testing Platform.
This is a sample repository containing test projects built with xUnit v3. The test projects are configured to use the new Microsoft Testing Platform (MTP) for enhanced testing capabilities.
The best setup for a test project is to look at Tests2
project file. See known issues at the bottom of this file for more details why.
The repository is configured to calculate code coverage using the Microsoft code coverage extension. For detailed documentation on this extension, see:
Code coverage results can be visualized using the Fine Code Coverage (FCC) Visual Studio extension.
.runsettings
file is currently disabled due to compatibility issues with the Fine Code Coverage (FCC) extension.
The extension is now creating its own .runsettings
file automatically when running the tests in Visual Studio with the Test Explorer.
This sample repository is based on the official xUnit v3 documentation:
- .NET 8 or later
- Visual Studio with Fine Code Coverage extension (optional, for coverage visualization). The extension is using it's default settings. This means that the setting
RunMsCodeCoverage
is set totrue
.
-
The Fine Code Coverage (FCC) extension is not showing the code coverage results of all the 3 test projects. It is showing only the results of the
Project1
andTests
projects. This is because of the configuration in the test project files. Test projectProject1
andTests
have the following package references:<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" /> <PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.14.2" /> <PackageReference Include="xunit.v3" Version="3.0.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
The
Tests2
project is missing theMicrosoft.NET.Test.Sdk
andxunit.runner.visualstudio
package references because they are not needed with MTP.After adding these package references to the
Tests2
project, the FCC extension is showing the code coverage results of all 3 test projects.