Search code examples
javascriptsonarqubesonarqube-scanistanbulsonarqube7

How does SonarQube calculate the overall coverage?


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.


Solution

  • 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