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¶
- Install ReportGenerator
Collect and view a Code Coverage Report.¶
- From command prompt: Go to folder where the .Test project you want to test is located
- Run dotnet test with coverage argument to specify XPlat Code Coverage:
> dotnet test --collect:"XPlat Code Coverage"
- 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
-reportsargument:
> 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
- The coverage report can now be viewed in a browser, for example by running:
> .\coveragereport\index.html
- Done!
Notes about future¶
- Can/should we migrate to
dotnet-coverageinstead, 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.