The Test Coverage Results Displayed in SonarCloud are Wrong

The Test Coverage Results Displayed in SonarCloud are Wrong

  • versions used : I am using SonarCloud
  • error observed: The Test Coverage Results Displayed in SonarCloud are Wrong
  • steps to reproduce
    1. Run Analyze Test Coverage for all tests in Visual Studio
    2. Run Sonar Cloud on the same Branch
      Results: The Sonar Cloud Test Coverage Result is 2.41% and the Visual Studio Enterprise Edition Test Coverage Result is 14.86%

So, what do we know so far:

  1. VS.Net Counts the number of lines differently then sonar cloud.
  2. Sonar Cloud uses its line count and the line coverage in each record from the report.
  3. On the develop branch, the resulting percentage from sonar cloud and are different by about a factor of 4, which is much greater than the factor of line count differences, which is less then 2. This means that we are missing something. My guess is that some of records from the report are not counted.
  4. The configurations were wrong for doing code coverage on pr’s until yesterday – I do not know if that is relevant for the develop branch itself.
  • There is no workaround

Hello Charles,

Our Coverage measure is a mix of the “Line Coverage %” and “Conditions Coverage %”, but you can also check those two measures separately in the “Measures” tab of your branch to check if those match what you see in Visual Studio.

You also probably want to make sure you narrowed the focus of your analysis in the same as what you see in Visual Studio, if different files are taken into account, for sure the measure will not match.

Thank you for your help. I see that our test execution results are not displaying. Could that be part of the problem?


What’s showing under “Tests” depends on which language your are analyzing (not all support this metric) and if your sonar.tests property is configured correctly (might be setup automatically if you use Maven or Gradle).

And it unrelated to the coverage measures. The coverage measure are filled up thanks to the coverage report that your passing to the scanner at the time of analyse. So you should check what’s in this file and if it matches the result of Visual Studio. If it doesn’t then you probably need to tweak the parameters of the tool you are using to generate the coverage report.

So, you cannot get the C# test execution results here? They are in the Azure Dev opts pipeline report.

It is working now. We were pointing to the wrong directory.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.