C# code coverage not getting picked up

Versions used:

  • SonarCloud
  • Jenkins 1.24.8
  • SonarScanner for MSBuild 5.2.2

Solution is C# .net 5.
I’ve read lots of posts and tried lots of different approaches, but I can’t seem to get the code coverage to appear in SonarQube.

Below are the commands that I am running in the build script

dotnet sonarscanner begin /o:ORG /key:KEY /d:sonar.cs.vstest.reportsPaths=./**/*TestResults.xml  /d:sonar.cs.opencover.reportsPath=./**/coverage.opencover.xml /d:sonar.verbose=true /d:sonar.branch.name=${env.BRANCH_NAME}
dotnet build
dotnet test --logger trx;LogFileName=BusinessTestResults.xml /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
dotnet sonarscanner end

Everything runs successfully and the issues and test results appear in SonarQube, but the code coverage remains 0.0%. I can confirm the coverage.opencover.xml file has been created and does exist. The logs (subset below) don’t seem to show any problems with picking up the file, but they also don’t provide any indication that it is even trying to find it.

10:55:21.563 INFO: ------------- Run sensors on project
10:55:21.576 DEBUG: 'C# Tests Coverage Report Import' skipped because one of the required properties is missing
10:55:21.576 DEBUG: '[Deprecated] C# Integration Tests Coverage Report Import' skipped because one of the required properties is missing
10:55:21.577 DEBUG: 'VB.NET' skipped because there is no related file in current project
10:55:21.577 DEBUG: 'VB.NET Tests Coverage Report Import' skipped because there is no related file in current project
10:55:21.577 DEBUG: '[Deprecated] VB.NET Integration Tests Coverage Report Import' skipped because there is no related file in current project
10:55:21.577 DEBUG: 'VB.NET Unit Test Results Import' skipped because there is no related file in current project
10:55:21.577 DEBUG: 'Java CPD Block Indexer' skipped because there is no related file in current project
10:55:21.577 DEBUG: Sensors : C# -> C# Unit Test Results Import -> Zero Coverage Sensor

Any help would be greatly appreciated.

Hi @MattvB,

C# Tests Coverage Report Import’ skipped because one of the required properties is missing

This message is logged if none of the test coverage parameters is set.

I think that /d:sonar.cs.opencover.reportsPath=./**/coverage.opencover.xml is missing an s. It should be /d:sonar.cs.opencover.reportsPaths=./**/coverage.opencover.xml instead.

That appears to have fixed it. Bit of a dumb mistake by me.
Thanks for the assistance!