Use Coverlet to view test coverage for. NET Core Applications

Source: Internet
Author: User
Tags dotnet

The Enterprise Edition of Visual Studio 2017 can see the code coverage of the tests directly, and since I can only afford Visual Studio community and VS code, I have to look for other ways to see test coverage.

Coverlet

I found it. coverlet: Https://github.com/tonerdo/coverlet, a library of cross-platform code coverage for. NET Core

Coverlet currently supports two modes of operation:

    1. Use the command as a global tool: dotnet tool install--global coverlet.console

      After installation, you can use the Coverlet command, see Help: coverlet--help, This I do not introduce, you can view the official documents.

    2. Add the library to the test project through the NuGet or dotnet CLI: dotnet Add Package Coverlet.msbuild. In this way, when it is enabled, it is integrated into the dotnet Test command architecture, which automatically generates coverage reports after the test runs.
Enable Coverlet

Very simply, execute the test command under the test project and add the following enabling parameters: dotnet test/p:collectcoverage=true .

The default report format is JSON.

Report Format

Coverlet also supports several other formats that can be specified by the coverletoutputformat parameter.

There are currently several formats supported:

    • JSON (default)
    • Lcov
    • Opencover
    • Cobertura

For example, to use the Opencover format: Then: dotnet test/p:collectcoverage=true /p:coverletoutputformat=opencover so write .

The default name of the report file it generates is:

Other parameters

Coverlet also has some other parameters, the use is very simple, please check the official documents: Https://github.com/tonerdo/coverlet#msbuild

View Reports

Coverlet can generate reports, but they are all JSON, XML, and other data formats that can only be seen through command-line windows. Some tools, such as reportgenerator or sonarcloud, are needed to see detailed reports that users can see.

Reportgenerator

Reportgenerator can be used locally, it supports opencover format, etc. in test Project installation: dotnet Add package reportgenerator--version 4.0.0- Alpha12

Follow the instructions after installation:

The commands I use on my computer are as follows: dotnet C:\Users\solen\.nuget\packages\reportgenerator\4.0.0-alpha12\tools\netcoreapp2.0\ Reportgenerator.dll-reports:.\coverage.opencover.xml-targetdir:f:\reports

Then go to the output directory and open index.htm:

Inside you can also click to do some things:

Sonarcloud

It's a cloud service, but the Java environment needs to be installed, and I don't want to bother about it. can go to the official website to know: https://sonarcloud.io/

This profile has been written ..... .....

Use Coverlet to view test coverage for. NET Core Applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.