Code coverage shown different than the one provided with 'Generic Test Data' format report

Hi everyone,
we are facing a problem with code coverage displayed in our Sonarqube Developer Edition v8.9.7.52159.

Let me briefly explain the process.

  • We are calculating the coverage of a .NET Core project using Coverlet and we configured it to ignore some paths, for example the EF Migration files.
  • After that we convert the report generated by Coverlet into a SonarQube report using a tool called reportGenerator.
  • The final SonarQube report is perfectly fine: it contains all the intended files and does not include the excluded files.
  • That file is the one we provide to SQ: in the sonarscanner begin we referenced it => /d:sonar.coverageReportPaths=“.\sonarqubecoverage\SonarQube.xml”

The problem is that, when we browse the coverage on SonarQube we actually see the coverage calculated for excluded files… and I can’t understand why.

I know that SonarQube also a sonar.coverage.exclusions property but I expect I don’t have to fill it because the SonarQube.xml report already has the correct file list.

What am I missing?

Best,
Alberto

If SonarQube receives no coverage data for a file (and no indication that a file should be excluded), it assumes that it should make a (very) educated guess about which lines are executable, and could therefore be covered by tests.

SonarQube does this for a good reason – if you have an application that is 50% .NET, and 50% JS, but you only provide a coverage report for .NET – that’s not indicative of the actual coverage for your entire project.

The best option is to pass these files to sonar.coverage.exclusions to make sure they aren’t counted towards your code coverage.

Hi Colin,
thank you, at least I understand the rational behind that choice.
Then, we’ll set the sonar.coverage.exclusions too.
Thank you again and best regards,
Alberto