Sonarqube coverage shows 0% in dashboard although coverage data is found for some .cs files

I am having issues with the code coverage metric in sonarqube:

  • Community Edition
  • Version 8.9.2 (build 46101)

The metric reads 0% coverage even though the scan detects coverage for some files.

I am generating the test coverage report files in opencover format.

I am using the dotnet global scanner tool (SonarScanner for .NET | SonarQube Docs) to scan the project.

Here is what is being ran:

dotnet sonarscanner begin -k:PPIL.WebAPI -d:sonar.coverage.exclusions="**/tests/**/*.cs" -d:sonar.cs.xunit.reportsPaths=TestResults/TestResults.xml -d:sonar.cs.opencover.reportsPaths=TestResults/**/*.opencover.xml -d:sonar.login=${TOKEN} -v:sonar.projectVersion= -d:sonar.log.level=DEBUG -d:sonar.verbose=true
dotnet build
dotnet test --collect:"XPlat Code Coverage" -r TestResults --logger:"xunit" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
dotnet sonarscanner end -d:sonar.login=${TOKEN}

Below is the output log which shows on line 1588 that the opencover report file is found and coverage data is found for some .cs files.

sonarscan_log.txt (239.4 KB)

Below are the contents of the TestResults folder.

TestResults.xml (1.0 MB)
coverage.opencover.xml (5.1 KB)

Below is a screenshot of the project dashboard.

Hi @SpaceCowboy1335,

I have analysed the logs that you attached. I didn’t see something strange.

But I notice that you are using

SonarScanner for MSBuild 5.1

The latest version is 5.3.2 which contains some improvements and bugfix for coverage. Would you like to have a try?

Moreover if you have a concrete example file without coverage while you believed it should be covered, please provide the full path so that we can investigate further.

Best regards,