Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 736
m-a-r-c-e-l-i-n-o Avatar asked Mar 08 '18 04:03

m-a-r-c-e-l-i-n-o


People also ask

How is code coverage calculated?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

What does coverage mean in SonarQube?

Metrics. SonarQube measures code quality based on different metrics. The most important metric is the code coverage metric. In this case, no tests have been written, which means you have no code coverage. The cool thing about SonarQube is that it indicates the number of lines that aren't covered by tests.

How does SonarQube improve code coverage?

to increase your code coverage, the suggestion is to write tests. It can be unit tests (easiest way) or other tests (Integration test, System tests) which may contribute to coverage when a tool can report coverage for these.

What does SonarQube measure?

SonarQube is a Code Quality Assurance tool that collects and analyzes source code, and provides reports for the code quality of your project. It combines static and dynamic analysis tools and enables quality to be measured continually over time.


1 Answers

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

like image 59
Tibor Blenessy Avatar answered Oct 13 '22 02:10

Tibor Blenessy