SonarQube Warning "Insufficient branch coverage with unit tests"

Does anyone know about the problem "Insufficient coverage of branches with unit tests"? At my code level, the code is 99%, but I still get a sonar warning for the same class "Insufficient branch coverage using unit tests: 111 more branches should be covered by unit tests to achieve a minimum branch coverage threshold of 65.0%" . Usually this error occurs due to insufficient coverage of the if / else condition, since we have to handle both positive / negative scenarios. Does anyone know anything else about this warning?

Thanks C

+4
source share
2 answers

This means that you have branches in your code that are not covered.

For instance:

boolean foo() {
  return a || b || c; 
}

if your tests always have true, then you really cover the line, but not all possible branches.

Also pay attention to the attempt to use resources, as this generates many branches in the bytecode (and you do not see them in the source), and you most likely do not cover them all.

+6
source

This is a good Wikipedia page explaining the differences between different reach indicators: link

Branch distribution in short if-else situations where you should test BOTH cases to cover 100%.

0
source

All Articles