11

enter image description here

The image above shows the SonarQube coverage for one of my folders, but if you take the average of the percentages of all files in that folder, it will amount to 49%, yet SonarQube will display 31.4%. If not by taking averages, how does SonarQube calculate the overall coverage? The same is true for all folders, even the top most one.

m-a-r-c-e-l-i-n-o
  • 2,622
  • 18
  • 26

1 Answers1

19

Overall coverage is calculated as

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 = lines_to_cover - uncovered_lines

B = total number of conditions
EL = total number of executable lines (lines_to_cover)

More details can be found in the documentation

Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63
Tibor Blenessy
  • 4,254
  • 29
  • 35
  • Thanks for the response, Tibor! I was aware of this portion and my question was more around how can the coverage percentage of a particular folder not be the aggregation of the coverage percentages of the files in that folder... In other words, the aggregation of the coverage percentages of all files in that folder amount to 49%, and yet, SonarQube displays 34%... Where is it getting 34% from? How is that possible? If you can answer that question, I will mark this answer as the accepted one. Thanks! – m-a-r-c-e-l-i-n-o Mar 09 '18 at 20:10
  • 2
    Overall coverage is computed with the same formula but over all files in the directory. It can not be just a simple average - imagine directory with two files, small 1 line file which is covered, and huge file with 1000 lines uncovered - simple average would be 50% overall coverage, which would be misleading – Tibor Blenessy Mar 20 '18 at 10:58
  • Yeah, makes sense now. Thank you for the explanation! – m-a-r-c-e-l-i-n-o Mar 29 '18 at 19:02
  • documentation link is not working – bhantol Sep 23 '21 at 19:21
  • 1
    @bhantol link is fixed now. – Ε Г И І И О Sep 26 '21 at 10:34