Konubinix' opinionated web of thoughts

What Implies 80% of Coverage in Sonar?

Fleeting

what implies 80% of coverage in sonar?

Imagine the situation where your code contains 100 lines and that you just setup sonar that asks for 80% of lines covered.

When discussing this with colleagues, I feel that most people think that it means “write tests so that 80 lines get covered”.

To me, this is a case of measure-objective inversion, where you consider that the goal is to make the indicator pass (see how you should use indicators?).

In my mind, it can also be that you write tests about only 40 lines and ignore 50 lines as considered not relevant is your code. Indeed, if the purpose of the indicator is to help you find out the state of your code and that you deem that 50 lines don’t need to be covered to fulfil that purpose, I don’t see why you would strive to test them. You could likely remove them, but that is another discussion I guess.

In brief, 80% of code coverage does not mean adding tests to cover 80% of the lines but rather ensure that at least 80% of the relevant lines get covered.

Notes linking here