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 can be used through three different drivers
Coverlet supports only SDK-style projects https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2019
At the moment collectors integration does not support .NET Framework application.
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 5 applications, you've only to update to last version if needed.
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.
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
dotnet add package coverlet.msbuild
N.B. You MUST add package only to test projects
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
dotnet tool install --global 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.
.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 Core 2.2 and above
Coverlet generates code coverage information by going through the following process:
Coverlet supports coverage for deterministic builds. The solution at the moment is not optimal and need a workaround.
Take a look at documentation.
Unfortunately we have some known issues, check it here
If you're using Cake Build for your build script you can use the Cake.Coverlet add-in to provide you extensions to dotnet test for passing Coverlet arguments in a strongly typed manner.
We offer nightly build of master for all packages. See the documentation
If you find a bug or have a feature request, please report them at this repository's issues section. See the CONTRIBUTING GUIDE for details on building and contributing to this project.
Author and owner
Co-maintainers
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.
For more information, see the .NET Foundation Code of Conduct.
Part of the code is based on work done by OpenCover team https://github.com/OpenCover
This project is licensed under the MIT license. See the LICENSE file for more info.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。