Skip to content

Code Coverage

Guidelines

...TODO

Run code coverage locally

It is possible to generate a code coverage report, which is useful to get a detailed report of what is / is not covered by the tests.

To generate the code coverage we use coverlet.collector which is installed as a Nuget.

Setup

  1. Install ReportGenerator

Collect and view a Code Coverage Report.

  1. From command prompt: Go to folder where the .Test project you want to test is located
  2. Run dotnet test with coverage argument to specify XPlat Code Coverage:

> dotnet test --collect:"XPlat Code Coverage"

  1. Run reportgenerator to convert the output into readable html. The dotnet test command will ahve printed out the path to the coverage report it generated. That should be input into the -reports argument:

> reportgenerator -reports:"C:\code\devops2\bank\bank-platform\Minority\Rebtel.Core.Infrastructure\Majority.Platform.Test\TestResults\b5c904d1-7ad5-4090-9311-847dec3454a9\coverage.cobertura.xml" -targetdir:"coveragereport/" -reporttypes:Html

  1. The coverage report can now be viewed in a browser, for example by running:

> .\coveragereport\index.html

  1. Done!

Notes about future

  • Can/should we migrate to dotnet-coverage instead, a tool provided by Microsoft?
  • To show coverage inline in Visual Studio, there's a plugin to VS called Fine Code Coverage. This however recommends to use dotnet-coverage and not coverlet to collect the data.