Coder Social home page Coder Social logo

coverlet's Introduction

Coverlet

Build Status

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.

Installation

VSTest Integration:

dotnet add package coverlet.collector

MSBuild Integration:

dotnet add package coverlet.msbuild

Global Tool:

dotnet tool install --global coverlet.console

Quick Start

VSTest Integration

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.json file containing the results will be published to the TestResults directory as an attachment. A summary of the results will also be displayed in the terminal.

See documentation for advanced usage.

Requirements

  • You need to be running .NET Core SDK v2.2.300 and above
  • You need to reference version 16.1.0 and above of Microsoft.NET.Test.Sdk
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />

MSBuild Integration

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

Requires a runtime that support .NET Standard 2.0 and above

Global Tool

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

.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

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.

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

Cake Add-In

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.

Consume nightly build

We offer nightly build of master for all packages. See the documentation

Issues & Contributions

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.

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's People

Contributors

tonerdo avatar marcorossignoli avatar sharwell avatar aarnott avatar derhally avatar viktorhofer avatar vagisha-nidhi avatar ido-namely avatar petli avatar sjp avatar amweiss avatar coenm avatar sasivishnu avatar obtuse-whoosh avatar jherby2k avatar hunterjm avatar tarekgh avatar gimmedakitty avatar pape77 avatar frankyboy avatar pms1969 avatar stephenmp avatar reptarsrage avatar nopara73 avatar viceice avatar lordmike avatar kolipka avatar xuhongxu96 avatar romanx avatar jzytnyk-korewireless avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.