Thursday, June 18, 2020

Dotnet Code Coverage for SonaQube

It's not that much hard.
If you are with dot net 2.0 or above then just execute the below command on your test project location.

(where the XXX.Test.csproj available.)

1).dotnet test --collect "Code Coverage"

Then the tests will get to execute and at last there will be a coverage file available as on the test result folder.

Attachments:
  C:\Program Files (x86)\Jenkins\workspace\Backend Dev\test\Api.Test\TestResults\88de1678-d457-4e6c-a3fd-2d5786cddc13\ar0_2020-06-18.10_24_43.coverage
Total tests: 132. Passed: 66. Failed: 57. Skipped: 9.
Test Run Failed.
Test execution time: 44.3640 Seconds

Then convert the .coverfile to coveragexml file using below command.

2).CodeCoverage analyze /output:VisualStudiot.coveragexml  ar0_2020-06-18.10_24_43.coverage

You can use below nuget command to download the CodeCoverage packages.

dotnet add package Microsoft.CodeCoverage --version 16.6.1


The just point the newly created coveragexml file to sonar server by below code.

3).sonar.cs.vscoveragexml.reportsPaths=C:/Development/VisualStudiot.coveragexml

No comments:

Post a Comment