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} -d:sonar.host.url=https://sonarqube.fis.dev -d:sonar.branch.name=development -v:sonar.projectVersion=1.0.0.0 -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.