SonarCloud does not report correct coverage

Hi all,

We have a WebAPI project written in C# and using Visual Studio 2022. We have also written unit test cases using xunit framework for the WebAPI project.

  • ALM used: Azure DevOps
  • CI system used: Azure DevOps
  • Languages of the repository: C#

The problem is that coverage running dotnet test is 87%, but on SonarCloud the value is 31%.
For generator the report, were used this following commands:

  • dotnet.exe test --configuration Release --logger trx --results-directory ./TestResults “–collect:Code Coverage” --filter Category!=TesteIntegrado --no-restore
  • codeCoverage.exe analyze /output:DynamicCodeCoverage.coveragexml code.coverage
  • reportgenerator “-reports:.\DynamicCodeCoverage.coveragexml” “-targetdir:pepiline-coveragereport” -reporttypes:Html

Local analyzis

SonarCloud Analyzis

Hey there.

A good first step is to find one specific example where SonarCloud indicates some code is not covered but your coverage report does – and work back from there. Can you find a specific example?