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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With