Coverlet
Cross platform code coverage for .NET
Install / Use
/learn @coverlet-coverage/CoverletREADME
Coverlet
| Driver | Current version | Downloads |
| --- | --- | --- |
| coverlet.MTP | |
|
| 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.
[!NOTE] Coverlet only supports modern .NET SDK-style projects.
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.
Main contents
- 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
Quick Start
Coverlet can be used through four different drivers
- VSTest engine integration
- MSBuild task integration
- As a .NET Global tool (supports standalone integration tests)
- New Microsoft Testing Platform integration (coverlet.MTP)
Coverlet supports only SDK-style projects https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2019
NEW Microsoft Testing Platform Integration (coverlet.MTP)
Installation (coverlet.MTP)
dotnet add package coverlet.MTP
[!NOTE] Add the
coverlet.MTPpackage only to test projects that use the Microsoft Testing Platform. This package is designed for projects usingMicrosoft.Testing.Platform(MTP) as the test runner, not the traditional VSTest runner.
Usage (coverlet.MTP)
Coverlet integrates with the Microsoft Testing Platform as an extension. To enable coverage collection, run your tests with the --coverlet flag:
dotnet run --project <your-test-project> -- --coverlet
Or when using dotnet test with MTP-enabled projects:
dotnet test --coverlet
After the above command is run, coverage report files will be generated in the test results directory. By default, reports are generated in json and cobertura formats.
Additional Options (coverlet.MTP)
| Option | Description |
| -------- | ------------- |
| --coverlet | Enable code coverage data collection |
| --coverlet-output-format | Output format(s) for coverage report (json, lcov, opencover, cobertura) |
| --coverlet-include | Include assemblies matching filters (e.g., [Assembly]Type) |
| --coverlet-exclude | Exclude assemblies matching filters (e.g., [Assembly]Type) |
| --coverlet-include-test-assembly | Include test assembly in coverage |
Example with options:
dotnet run --project <your-test-project> -- --coverlet --coverlet-output-format cobertura --coverlet-exclude "[xunit.]"
Requirements (coverlet.MTP)
- .NET 8.0 SDK or newer
- Test project configured for Microsoft Testing Platform
VSTest Integration (preferred due to known issue)
Installation (coverlet.collector)
dotnet add package coverlet.collector
[!NOTE] You MUST add package only to test projects and if you create xunit test projects (
dotnet new xunit) you will find the reference already present incsprojfile because Coverlet is the default coverage tool for every .NET Core and >= .NET 8 applications, you've only to update to last version if needed. Addcoverlet.collectorORcoverlet.msbuildpackage in a test project.
Usage (coverlet.collector)
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.
Requirements (coverlet.collector)
- .NET 8.0 SDK is required (version 8.0.112 or higher)
- Microsoft.NET.Test.Sdk version 17.12.0 or higher
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
MSBuild Integration (suffers of possible known issue)
Installation (coverlet.msbuild)
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.
Usage (coverlet.msbuild)
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.
Requirements (coverlet.msbuild)
- .NET 8.0 SDK is required (version 8.0.112 or higher)
- .NET Framework that supports .NET Standard 2.0
.NET Global Tool (guide, suffers from possible known issue)
Installation (coverlet.console)
dotnet tool install --global coverlet.console
Usage (coverlet.console)
The coverlet tool is invoked by specifying the path to the assembly that contains the unit tests. You also need to specify the test runner and the arguments to pass to the test runner using the --target and --targetargs options respectively. The invocation of the test runner with the supplied arguments must not involve a recompilation of the unit test assembly or no coverage result will be generated.
The following example shows how to use the familiar dotnet test toolchain:
coverlet /path/to/test-assembly.dll --target "dotnet" --targetargs "test /path/to/test-project --no-build"
Note: The --no-build flag is specified so that the /path/to/test-assembly.dll assembly isn't rebuilt
See documentation for advanced usage.
Requirements (coverlet.console)
- .NET global tools rely on a .NET Core runtime installed on your machine https://docs.microsoft.com/en-us/dotnet/core/tools/global-tools#what-could-go-wrong
- .NET Coverlet global tool requires .NET 8.0 or above
How It Works
Coverlet generates code coverage information by going through the following process:
Before Tests Run
- Locates the unit test assembly and selects all the referenced assemblies that have PDBs.
- Instruments the selected assemblies by inserting code to record sequence point hits to a temporary file.
After Tests Run
- Restore the original non-instrumented assembly files.
- Read the recorded hits information from the temporary file.
- Generate the coverage result from the hits information and write it to a file.
Deterministic build support
Coverlet supports coverage for deterministic builds. The solution at the moment is not optimal and need a workaround. Take a look at documentation.
Are you in trouble with some feature? Check on examples
Known Issues
Unfortunately we have some known issues
Cake Add-In
If you're using Cake Build for your build script you can use the [Cake.Coverlet](ht
Related Skills
node-connect
333.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
333.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.0kCommit, push, and open a PR
