Driver | Current version | Downloads |
---|---|---|
coverlet.collector | ||
coverlet.msbuild | ||
coverlet.console |
Coverlet is a cross platform code coverage framework for .NET, with support for line, branch and method coverage. It works with .NET Framework on Windows and .NET Core on all supported platforms.
Coverlet documentation reflect the current repository state of the features, not the released ones. Check the changelog to understand if the documented feature you want to use has been officially released.
- QuickStart
- How It Works
- Drivers features differences
- Deterministic build support
- Known Issues
- Consume nightly build
- Feature samples
- Cake Add-In
- Visual Studio Add-In
- Changelog
- Roadmap
Coverlet can be used through three different drivers
- VSTest engine integration
- MSBuild task integration
- As a .NET Global tool (supports standalone integration tests)
Coverlet supports only SDK-style projects https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2019
VSTest Integration (preferred due to known issue)
dotnet add package coverlet.collector
N.B. You MUST add package only to test projects and if you create xunit test projects (dotnet new xunit
) you'll find the reference already present in csproj
file because Coverlet is the default coverage tool for every .NET Core and >= .NET 6 applications, you've only to update to last version if needed. Do not add coverlet.collector
and coverlet.msbuild
package in a test project.
Coverlet is integrated into the Visual Studio Test Platform as a data collector. To get coverage simply run the following command:
dotnet test --collect:"XPlat Code Coverage"
After the above command is run, a coverage.cobertura.xml
file containing the results will be published to the TestResults
directory as an attachment.
See documentation for advanced usage.
- You need to be running .NET 6.0 SDK v6.0.316 or newer
- You need to reference version 17.5.0 and above of Microsoft.NET.Test.Sdk
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
MSBuild Integration (suffers of possible known issue)
dotnet add package coverlet.msbuild
N.B. Typically you MUST add package only to test projects. Do not add coverlet.msbuild
and coverlet.collector
package in a test project.
Coverlet also integrates with the build system to run code coverage after tests. Enabling code coverage is as simple as setting the CollectCoverage
property to true
dotnet test /p:CollectCoverage=true
After the above command is run, a coverage.json
file containing the results will be generated in the root directory of the test project. A summary of the results will also be displayed in the terminal.
See documentation for advanced usage.
Requires a runtime that support .NET Standard 2.0 and above
.NET Global Tool (guide, suffers from possible known issue)
dotnet tool install --global coverlet.console