coverlet.msbuild 1.2.0

Coverlet is a cross platform code coverage library for .NET Core, with support for line, branch and method coverage.

There is a newer version of this package available.
See the version list below for details.
Install-Package coverlet.msbuild -Version 1.2.0
dotnet add package coverlet.msbuild --version 1.2.0
<PackageReference Include="coverlet.msbuild" Version="1.2.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add coverlet.msbuild --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

coverlet Build Status Build status Coverage Status License: MIT

Coverlet is a cross platform code coverage library for .NET Core, with support for line, branch and method coverage.

Installation

Available on NuGet

Visual Studio:

PM> Install-Package coverlet.msbuild

.NET Core CLI:

dotnet add package coverlet.msbuild

How It Works

Coverlet integrates with the MSBuild system and that allows it to go 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.

Note: The assembly you'd like to get coverage for must be different from the assembly that contains the tests

Usage

Coverlet doesn't require any additional setup other than including the NuGet package in the unit test project. It integrates with the dotnet test infrastructure built into the .NET Core CLI and when enabled, will automatically generate coverage results after tests are run.

Code Coverage

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.

Coverage Output

Coverlet can generate coverage results in multiple formats, which is specified using the CoverletOutputFormat property. For example, the following command emits coverage results in the opencover format:

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover

Supported Formats:

  • json (default)
  • lcov
  • opencover
  • cobertura

The output folder of the coverage result file can also be specified using the CoverletOutputDirectory property.

Threshold

Coverlet allows you to specify a coverage threshold below which it fails the build. This allows you to enforce a minimum coverage percent on all changes to your project.

dotnet test /p:CollectCoverage=true /p:Threshold=80

The above command will automatically fail the build if the average code coverage of all instrumented modules falls below 80%.

Excluding From Coverage

Attributes

You can ignore a method or an entire class from code coverage by creating and applying any of the following attributes:

  • ExcludeFromCoverage
  • ExcludeFromCoverageAttribute

Coverlet just uses the type name, so the attributes can be created under any namespace of your choosing.

Source Files

You can also ignore specific source files from code coverage using the Exclude property

  • Use single or multiple paths (separate by comma)
  • Use absolute or relative paths (relative to the project directory)
  • Use file path or directory path with globbing (e.g dir1/*.cs)
dotnet test /p:CollectCoverage=true /p:Exclude=\"../dir1/class1.cs,../dir2/*.cs,../dir3/**/*.cs,\"

Roadmap

  • Filter modules to be instrumented
  • Support for more output formats (e.g. JaCoCo)
  • Console runner (removes the need for requiring a NuGet package)

Issues & Contributions

If you find a bug or have a feature request, please report them at this repository's issues section. Contributions are highly welcome, however, except for very small changes, kindly file an issue and let's have a discussion before you open a pull request.

Building The Project

Clone this repo:

git clone https://github.com/tonerdo/coverlet

Change directory to repo root:

cd coverlet

Execute build script:

dotnet msbuild build.proj

This will result in the following:

  • Restore all NuGet packages required for building
  • Build and publish all projects. Final binaries are placed into &lt;repo_root&gt;\build\&lt;Configuration&gt;
  • Build and run tests

These steps must be followed before you attempt to open the solution in an IDE (e.g. Visual Studio, Rider) for all projects to be loaded successfully.

Code of Conduct

This project enforces a code of conduct in line with the contributor covenant. See CODE OF CONDUCT for details.

License

This project is licensed under the MIT license. See the LICENSE file for more info.

coverlet Build Status Build status Coverage Status License: MIT

Coverlet is a cross platform code coverage library for .NET Core, with support for line, branch and method coverage.

Installation

Available on NuGet

Visual Studio:

PM> Install-Package coverlet.msbuild

.NET Core CLI:

dotnet add package coverlet.msbuild

How It Works

Coverlet integrates with the MSBuild system and that allows it to go 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.

Note: The assembly you'd like to get coverage for must be different from the assembly that contains the tests

Usage

Coverlet doesn't require any additional setup other than including the NuGet package in the unit test project. It integrates with the dotnet test infrastructure built into the .NET Core CLI and when enabled, will automatically generate coverage results after tests are run.

Code Coverage

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.

Coverage Output

Coverlet can generate coverage results in multiple formats, which is specified using the CoverletOutputFormat property. For example, the following command emits coverage results in the opencover format:

dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover

Supported Formats:

  • json (default)
  • lcov
  • opencover
  • cobertura

The output folder of the coverage result file can also be specified using the CoverletOutputDirectory property.

Threshold

Coverlet allows you to specify a coverage threshold below which it fails the build. This allows you to enforce a minimum coverage percent on all changes to your project.

dotnet test /p:CollectCoverage=true /p:Threshold=80

The above command will automatically fail the build if the average code coverage of all instrumented modules falls below 80%.

Excluding From Coverage

Attributes

You can ignore a method or an entire class from code coverage by creating and applying any of the following attributes:

  • ExcludeFromCoverage
  • ExcludeFromCoverageAttribute

Coverlet just uses the type name, so the attributes can be created under any namespace of your choosing.

Source Files

You can also ignore specific source files from code coverage using the Exclude property

  • Use single or multiple paths (separate by comma)
  • Use absolute or relative paths (relative to the project directory)
  • Use file path or directory path with globbing (e.g dir1/*.cs)
dotnet test /p:CollectCoverage=true /p:Exclude=\"../dir1/class1.cs,../dir2/*.cs,../dir3/**/*.cs,\"

Roadmap

  • Filter modules to be instrumented
  • Support for more output formats (e.g. JaCoCo)
  • Console runner (removes the need for requiring a NuGet package)

Issues & Contributions

If you find a bug or have a feature request, please report them at this repository's issues section. Contributions are highly welcome, however, except for very small changes, kindly file an issue and let's have a discussion before you open a pull request.

Building The Project

Clone this repo:

git clone https://github.com/tonerdo/coverlet

Change directory to repo root:

cd coverlet

Execute build script:

dotnet msbuild build.proj

This will result in the following:

  • Restore all NuGet packages required for building
  • Build and publish all projects. Final binaries are placed into &lt;repo_root&gt;\build\&lt;Configuration&gt;
  • Build and run tests

These steps must be followed before you attempt to open the solution in an IDE (e.g. Visual Studio, Rider) for all projects to be loaded successfully.

Code of Conduct

This project enforces a code of conduct in line with the contributor covenant. See CODE OF CONDUCT for details.

License

This project is licensed under the MIT license. See the LICENSE file for more info.

Dependencies

This package has no dependencies.

Showing the top 10 GitHub repositories that depend on coverlet.msbuild:

Repository Stars
dotnet/machinelearning
ML.NET is an open source and cross-platform machine learning framework for .NET.
ardalis/CleanArchitecture
A starting point for Clean Architecture with ASP.NET Core
dotnet/winforms
Windows Forms is a .NET Core UI framework for building Windows desktop applications.
tmenier/Flurl
Fluent URL builder and testable HTTP client for .NET
StephenCleary/AsyncEx
A helper library for async/await.
lunet-io/markdig
A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
tonerdo/coverlet
Cross platform code coverage for .NET
dotnet/spark
.NET for Apache® Spark™ makes Apache Spark™ easily accessible to .NET developers.
skoruba/IdentityServer4.Admin
The administration for the IdentityServer4 and Asp.Net Core Identity
filipw/dotnet-script
Run C# scripts from the .NET CLI.

Version History

Version Downloads Last updated
2.6.3 425,219 7/1/2019
2.6.2 207,297 6/6/2019
2.6.1 307,983 5/8/2019
2.6.0 528,803 3/4/2019
2.5.1 766,400 1/17/2019
2.5.0 215,495 12/20/2018
2.4.0 346,698 11/28/2018
2.3.2 129,897 11/19/2018
2.3.1 414,489 10/16/2018
2.3.0 484,244 9/7/2018
2.2.1 263,681 8/11/2018
2.1.1 210,287 7/16/2018
2.1.0 78,212 7/6/2018
2.0.1 172,026 6/12/2018
2.0.0 58,981 5/17/2018
1.2.0 50,885 5/2/2018
1.1.1 42,734 4/17/2018
1.1.0 2,269 4/16/2018
1.0.2 23,170 4/2/2018
1.0.1 7,959 3/26/2018
1.0.0 3,941 3/21/2018
Show less