How does SonarQube compute the coverage?

Hi all!

I’m trying to understand how SonarQube compute the coverage. In my C++ project I see that on the overall code I have:

  • Coverage: 47.6 %
  • Line Coverage 70.8 %
  • Condition Coverage 36.2 %

I’m using gcovr to generate coverage in sonaqube format, the last two lines matches with my local report, but I have no idea how sonarqube generate the first coverage reported above.

Take a look here:

Coverage (coverage): A mix of Line coverage and Condition coverage. It’s goal is to provide an even more accurate answer the question ‘How much of the source code has been covered by the unit tests?’.

Coverage = (CT + CF + LC)/(2*B + EL)
where:

  • CT = conditions that have been evaluated to ‘true’ at least once
  • CF = conditions that have been evaluated to ‘false’ at least once
  • LC = covered lines = linestocover - uncovered_lines
  • B = total number of conditions
  • EL = total number of executable lines (lines_to_cover)

That’s clear! Thank you :smiley:

1 Like