1
votes

I analyzed a project with SonarQube 6.3, and it gave me the error:

32 more lines of code need to be covered by tests to reach the minimum threshold of 65.0% lines coverage

It's related to the rule:

Lines should have sufficient coverage by tests

I would like to know if this rule covers all type of tests that I make, or a specific one or does it mean that SonarQube could not reach those lines to analyze.

The reason I am asking this is I don't have tests at all, so this issue message could mean that SonarQube could recognize some tests for other lines which is not the case, so how could that happen?

1

1 Answers

0
votes

Starting from 6.2, SonarQube enables the ability to recognize "executable lines" in code files whether or not there are any tests in the files. The feature must also be supported and fed by your analyzer. I'm guessing you're using an analyzer version that does provide that data, and that's where you're getting the calculation of missing coverage on these files that are untouched by unit tests.

Note that before this functionality was added, the situation looked something like this

+--------------+-----------+-------+
|     File     | Cvd lines | Cvg % |
+--------------+-----------+-------+
| 100LineFile  |        75 |   75  |
+--------------+-----------+-------+
| Total        |        75 |   75  |
+--------------+-----------+-------+

AND

+--------------+-----------+-------+
|     File     | Cvd lines | Cvg % |
+--------------+-----------+-------+
| 100LineFile  |        75 |   75  |
| 100LineFile2 |         0 |    -  |
+--------------+-----------+-------+
| Total        |        75 |   75  |
+--------------+-----------+-------+

Because files that weren't touched by any unit tests were simply omitted from the calculations, giving a falsely rosy picture of overall coverage. Now it looks like this:

+--------------+-----------+-------+
|     File     | Cvd lines | Cvg % |
+--------------+-----------+-------+
| 100LineFile  |        75 |   75  |
| 100LineFile2 |         0 |    0  |
+--------------+-----------+-------+
| Total        |        75 |   37.5|
+--------------+-----------+-------+