SonarQube UT coverage is different from VS coverage

Hi,

We use SonarQube 9.3.0.51899.
We have a C# .NET core project with 100% branch coverage of the unit tests.
When we execute the UT and import the report to SQ, the coverage is 30%.

These are the steps in the process:

  • downloaded dotnet-sdk-3.1.417-linux-x64.tar.gz

  • dotnet sonarscanner begin /k:"${params.Microservice}" /v:${build_version} /n:"${params.Microservice}" /d:sonar.coverageReportPaths=“sonarqubecoverage/SonarQube.xml” /d:sonar.branch.name=${params.Branch} /d:sonar.qualitygate.wait=true (with builder dotnet)

  • dotnet build (with builder dotnet)

./dotnet test --no-build “file.sln” --collect:“XPlat Code Coverage” (with downloaded dotnet)

reportgenerator “-reports:/TestResults//coverage.cobertura.xml” “-targetdir:sonarqubecoverage” “-reporttypes:SonarQube”

dotnet sonarscanner end (with builder dotnet)

Can you please advise?

Thanks in advanced,
Gal

Hi,

Welcome to the community!

Do you have in-code coverage exclusions? SonarQube doesn’t read/honor those. You would need to re-configure them in SonarQube. Additionally, we calculate what we call executable lines, and use them in the denominator of the math. This blog post explains how it works and what the impact is.

 
HTH,
Ann