3

I'm trying to add the code coverage to sonarqube, the tests are included and executed but percentage of coverage is 0.0.

In my pipeline I got "Prepare analysis on SonarQube" and the project key well configured in the additional Properties I put "sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml" but nothing changed, I also tried without this.

Other step is "VsTest - testAssemblies" in which I selected my unit test and selected the Code coverage enabled box and two more steps with "Run Code Analysis" and "Publish Quality Gate Result" this two steps are like default, I tried to augment the timeout but nothing changed.

The output log in "VsTest - testAssemblies" was

Results File: X:\VSTSWork\52\s\TestResults\PRO_2019-05-09_20_07_48.trx

Attachments:
  X:\VSTSWork\52\s\TestResults\cdb1f30e-3958-4155-81e4-caa54693dfe9\PRO 2019-05-09 20_06_39.coverage

Total tests: 25. Passed: 25. Failed: 0. Skipped: 0.
Test Run Successful.

and in "Run Code Analysis"

20:08:05.303  Fetching code coverage report information from TFS...
20:08:05.308  Attempting to locate a test results (.trx) file...
20:08:05.364  Looking for TRX files in: X:\VSTSWork\52\TestResults, X:\VSTSWork\52\s\TestResults
20:08:05.366  The following test results files were found: X:\VSTSWork\52\s\TestResults\PRO_2019-05-09_20_07_48.trx
20:08:05.433  The following code coverage attachments were found from the trx files: X:\VSTSWork\52\s\TestResults\PRO_2019-05-09_20_07_48\In\PRO\PRO 2019-05-09 20_06_39.coverage
WARNING: File 'C:\Users\pro\.nuget\packages\runtime.win-x64.microsoft.netcore.dotnethostpolicy\2.1.0\runtimes\win-x64\native\hostpolicy.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
WARNING: File 'C:\Users\pro\.nuget\packages\runtime.win-x64.microsoft.netcore.dotnethostresolver\2.1.0\runtimes\win-x64\native\hostfxr.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
WARNING: File 'C:\Users\pro\.nuget\packages\xunit.runner.visualstudio\2.3.1\build\netcoreapp1.0\xunit.runner.visualstudio.dotnetcore.testadapter.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
WARNING: File 'C:\Users\pro\.nuget\packages\xunit.runner.visualstudio\2.3.1\build\netcoreapp1.0\xunit.runner.reporters.netcoreapp10.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
WARNING: File 'C:\Users\pro\.nuget\packages\xunit.runner.visualstudio\2.3.1\build\netcoreapp1.0\xunit.runner.utility.netcoreapp10.dll' is not located under the root directory 'X:\VSTSWork\52\s' and will not be analyzed.
Calling the SonarQube Scanner...
.
..
...

INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the Visual Studio coverage XML report X:\VSTSWork\52\.\s\TestResults\PRO_2019-05-09_20_07_48\In\PRO\PRO 2019-05-09 20_06_39.coveragexml
INFO: Adding this code coverage report to the cache for later reuse: X:\VSTSWork\52\.\s\TestResults\PRO_2019-05-09_20_07_48\In\PRO\PRO 2019-05-09 20_06_39.coveragexml
WARN: The Code Coverage report doesn't contain any coverage data for the included files. For troubleshooting hints, please refer to https://docs.sonarqube.org/x/CoBh
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=3701ms
INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the Visual Studio Test Results file X:\VSTSWork\52\s\TestResults\PRO_2019-05-09_20_07_48.trx
INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=64ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=363ms
INFO: Sensor CPD Block Indexer
INFO: Sensor CPD Block Indexer (done) | time=0ms
INFO: 49 files had no CPD blocks
INFO: Calculating CPD for 128 files
INFO: CPD calculation finished
INFO: Analysis report generated in 7191ms, dir size=810 KB
INFO: Analysis reports compressed in 1207ms, zip size=501 KB
INFO: Analysis report uploaded in 89ms
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
delfosk9
  • 73
  • 1
  • 9
  • `WARN: The Code Coverage report doesn't contain any coverage data for the included files. For troubleshooting hints, please refer to https://docs.sonarqube.org/x/CoBh`. Did you start by reading the linked documentation and trying the suggestions in there? – Daniel Mann May 09 '19 at 18:30
  • Yes, and I tried to insert something like that d:propertyKey="path" without any succes – delfosk9 May 09 '19 at 18:38
  • One of my tries was this /d:sonar.verbose=true /d:sonar.cs.vscoveragexml.reportsPaths=**/* – delfosk9 May 09 '19 at 18:44

1 Answers1

2

Finally, I found what was going bad,

It solves for me when I add:

<DebugType>Full</DebugType>

In the .csproj. The odd thing is that the other projects reported some code coverage without this property so I thought I didn't need it.

So if the reported coverage seems false, try adding this property in the csproj.

I found this in Publish test coverage of multiple .NET Core Projects from Azure DevOps to SonarQube server

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
delfosk9
  • 73
  • 1
  • 9