Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SonarQube what is the difference in meaning between the "Lines to Cover" and "Uncovered Lines" metrics?

I am looking at the Coverage report within the Measures tab of a SonarQube analysed C++ project. On that page my summary information is as follows:

SonarQube Coverage Overview

What are the differences between the "Lines to Cover" and "Uncovered Lines" metrics?

I have looked on the sonarqube website's Metric Definitions page but the two entries there to do not help me.

Lines to cover - Number of lines of code which could be covered by unit tests (for example, blank lines or full comments lines are not considered as lines to cover).

Uncovered lines - Number of lines of code which are not covered by unit tests.

The way that reads, I would expect that Uncovered Lines would be a higher count than the Lines to cover number, as the former might include blank lines. If sonarqube understood the code somewhat it might also exclude exception handling from the "could be covered by unit tests" number as well.

The given numbers are clearly a reverse of that, so I must not be understanding the meaning correctly.


I have some unit tests run as part of the CI system and their code coverage is compilated using both lcov and gcov. The lcov data is passed through genhtml to make separate coverage report which currently gives data in some cases, so I may have partial misconfiguration issue adding to the confusion.

like image 607
TafT Avatar asked Sep 19 '18 12:09

TafT


People also ask

What does coverage mean in SonarQube?

Code coverage, also called test coverage, is a measure of how much of the application's code has been run in testing. Essentially, it's a metric that many teams use to check the quality of their tests because it represents the percentage of the production code that has been tested and run.

What is conditions to cover in SonarQube?

SonarQube describes the "Condition" coverage like this: On each line of code containing some boolean expressions, the condition coverage simply answers the following question: 'Has each boolean expression been evaluated both to true and false?' .

How do I increase line coverage in SonarQube?

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.


1 Answers

"Lines to Cover" are the total lines in your "production" code that you should, in a so-called perfect world, have tests for. This is every line in source code files, which is not a comment, blank or similar non-code line.

In the real world, your tests will only cover some of these. The lines that are missed are the "Uncovered Lines".

In other words, you can express "Coverage" as:

"Coverage" = 100% - 100 * "Uncovered Lines" / "Lines to Cover"
like image 138
Mureinik Avatar answered Sep 19 '22 14:09

Mureinik