SonarCloud code coverage showing 0%

We are using SonarCloud to analyze projects through Azure DevOps. We recently created a new build pipeline and SonarCloud project. The SonarCloud project was created manually. Other than the code coverage, the project/pipeline functions properly. The code coverage is saying 0%, but the same code/tests are recognized on our other SonarCloud projects. The analysis and testing tasks have been set up in Azure DevOps as the documentation describes.

Here is the beginning of the Run Analysis log:

Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 1.19.0
Author       : sonarsource
Help         : Version: 1.19.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](https://sonarcloud.io/documentation/analysis/scan/sonarscanner-for-azure-devops/)
==============================================================================
D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.16.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 5.0.4
Using the .NET Framework version of the Scanner for MSBuild

Here is where the code coverage tool runs. This log is consistent with our working SonarCloud pipelines/projects.

17:19:35.605  Writing processing summary to D:\a\1\.sonarqube\out\ProjectInfo.log
Calling the TFS Processor executable...
Executing file D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.16.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.TFSProcessor.exe
  Args: ConvertCoverage D:\a\1\.sonarqube\conf\SonarQubeAnalysisConfig.xml D:\a\1\.sonarqube\out\sonar-project.properties 
  Working directory: D:\a\1
  Timeout (ms):-1
  Process id: 2280
Attempting to locate the CodeCoverage.exe tool...
Attempting to locate the CodeCoverage.exe tool using setup configuration...
Code coverage command line tool: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
Fetching code coverage report information from TFS...
Attempting to locate a test results (.trx) file...
Looking for TRX files in: D:\a\1\TestResults
No test results files found
Did not find any binary coverage files in the expected location.
Falling back on locating coverage files in the agent temp directory.
Searching for coverage files in D:\a\_temp
All matching files: count=2
	D:\a\_temp\TestResults\0cec16ea-f00e-418a-9704-95a79c4577f4\VssAdministrator_WIN-2JAVS1DFC0O_2020-12-01.17_18_42.coverage
	D:\a\_temp\TestResults\VssAdministrator_WIN-2JAVS1DFC0O_2020-12-01_17_19_05\In\WIN-2JAVS1DFC0O\VssAdministrator_WIN-2JAVS1DFC0O_2020-12-01.17_18_42.coverage
Unique coverage files: count=1
	D:\a\_temp\TestResults\0cec16ea-f00e-418a-9704-95a79c4577f4\VssAdministrator_WIN-2JAVS1DFC0O_2020-12-01.17_18_42.coverage
Executing file C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
  Args: analyze /output:D:\a\_temp\TestResults\0cec16ea-f00e-418a-9704-95a79c4577f4\VssAdministrator_WIN-2JAVS1DFC0O_2020-12-01.17_18_42.coveragexml D:\a\_temp\TestResults\0cec16ea-f00e-418a-9704-95a79c4577f4\VssAdministrator_WIN-2JAVS1DFC0O_2020-12-01.17_18_42.coverage 
  Working directory: D:\a\_temp\TestResults\0cec16ea-f00e-418a-9704-95a79c4577f4
  Timeout (ms):60000
  Process id: 1868
Process returned exit code 0
Coverage report conversion completed successfully.
Process returned exit code 0
The TFS Processor has finished

Here is the end of the log. It appears as though SonarScanner is saying there are no coverage files.

17:21:16.733 INFO: Importing 23 Roslyn reports
17:21:16.872 INFO: Sensor C# [csharp] (done) | time=2180ms
17:21:16.873 INFO: Sensor C# Tests Coverage Report Import [csharp]
17:21:16.874 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir 'D:\a\1\.' and file separator '\'.
17:21:16.877 DEBUG: Pattern matcher extracted prefix/absolute path 'D:\a' from the given pattern 'D:\a\_temp/**/*.coveragexml'.
17:21:16.879 DEBUG: Gathering files for wildcardPattern '_temp/**/*.coveragexml'.
17:21:24.580 DEBUG: Pattern matcher returns '1' files.
17:21:24.580 DEBUG: The current user dir is 'D:\a\1'.
17:21:24.581 INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\TestResults\0cec16ea-f00e-418a-9704-95a79c4577f4\VssAdministrator_WIN-2JAVS1DFC0O_2020-12-01.17_18_42.coveragexml
...some DEBUG messages...
17:21:25.258 INFO: Adding this code coverage report to the cache for later reuse: D:\a\_temp\TestResults\0cec16ea-f00e-418a-9704-95a79c4577f4\VssAdministrator_WIN-2JAVS1DFC0O_2020-12-01.17_18_42.coveragexml
17:21:25.258 DEBUG: Analyzing coverage after aggregate found '0' coverage files.
17:21:25.258 DEBUG: The total number of file count statistics is '0'.
17:21:25.258 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=8385ms
17:21:25.258 INFO: Sensor Zero Coverage Sensor
17:21:25.328 INFO: Sensor Zero Coverage Sensor (done) | time=70ms

I have tried setting the following (individually):

sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/Sonar***.trx
sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)/**/*.coveragexml

but it has not helped.

I have also set verbose logging:

sonar.verbose=true

Hi @danieljosephh and welcome to the community.

So what is the difference between the one that works and this one ?

Can you make sure that file paths inside the coveragexml matches the one that you have on your build pipeline ?

Mickaƫl

Thank you @mickaelcaro

The project/pipeline that works is analyzing our full application and all tests.

The project/pipeline that does NOT work is analyzing a subset of the application and all tests associated with it. There are more exclusions in this case because the dependencies will be analyzed in there own projects.

How can I access the coveragexml files? Can I create a task in Azure DevOps to send the coveragexml file some place, or email it?

If you are using a Microsoft Hosted agent, you can publish the coverage file as an artifact (See the task Publish build artifact) You will then be able to download it from your build summary.

HTH,
Mickaƫl

I was able to download the .coveragexml files for both pipelines. For the projects that the new pipeline is concerned with, the coverage is the same:

coveragexml from NOT working pipeline:

<module name="project.infrastructure.dll" path="project.infrastructure.dll" id="635BA6B1125E6A4C8F6CB4A530959B8001000000" block_coverage="95.31" line_coverage="95.20" blocks_covered="1139" blocks_not_covered="56" lines_covered="4744" lines_partially_covered="0" lines_not_covered="239">
<module name="project.interfaces.dll" path="project.interfaces.dll" id="893373305832984295679EA8FB075A9301000000" block_coverage="100.00" line_coverage="100.00" blocks_covered="3" blocks_not_covered="0" lines_covered="3" lines_partially_covered="0" lines_not_covered="0">
<module name="project.web.dll" path="project.web.dll" id="980D060A03515042A3D981193D742FD901000000" block_coverage="34.18" line_coverage="39.91" blocks_covered="108" blocks_not_covered="208" lines_covered="655" lines_partially_covered="0" lines_not_covered="986">

coveragexml from working pipeline:

<module name="project.infrastructure.dll" path="project.infrastructure.dll" id="64DE8FDEBBBF0F41B056D9433AE885C801000000" block_coverage="95.31" line_coverage="95.20" blocks_covered="1139" blocks_not_covered="56" lines_covered="4744" lines_partially_covered="0" lines_not_covered="239">
<module name="project.interfaces.dll" path="project.interfaces.dll" id="88E43B165D251B4B899FEF43CEB50D4B01000000" block_coverage="100.00" line_coverage="100.00" blocks_covered="3" blocks_not_covered="0" lines_covered="3" lines_partially_covered="0" lines_not_covered="0">
<module name="project.web.dll" path="project.web.dll" id="73F9DD2E35346F478B91BEDABEF1E30101000000" block_coverage="34.18" line_coverage="39.91" blocks_covered="108" blocks_not_covered="208" lines_covered="655" lines_partially_covered="0" lines_not_covered="986">

I have a suspicion that I am accidentally omitting these files from the analysis, but I have not added the folder that these 3 modules exist in to any exclusion.

Can you check at the files paths inside those coverage file, to see if they are quite the same as well please ?

We currently ignore those numbers, as we have our own way to determine coverage.

Thanks !

Ahh. The file paths are different.

Coveragexml that works has paths like:

<source_files>
        <source_file id="0" path="D:\a\1\s\src\..." checksum_type="unknown">
        </source_file>
</source_files>

Coveragexml that does not work has paths like:

<source_files>
        <source_file id="0" path="C:\s\src\..." checksum_type="unknown">
        </source_file>
</source_files>

Oh so i think that comes from here.

Do you have by chance any /p:PathMap parameter in your msbuild commandline ?

In the MSBuild for the working pipeline there is no /p:PathMap.

In the MSBuild of the NOT working pipeline, there is a /p:PathMap=D:\a\1=C:\

I tried removing the /p:PathMap=D:\a\1=C:\ and the coverage analysis still shows 0%

Can you check in the logs (preferably in debug mode) if there is something about coverage import ?

Ahh, in the end it was the /p:PathMap that was the culprit.

I had modified

sonar.cs.vscoveragexml.reportsPaths
sonar.cs.vscoveragexml.it.reportsPaths

yesterday and forgot to undo the changes.

The code coverage is working as expected now.

Merci bien, @mickaelcaro!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.