Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube warning "Insufficient branch coverage by unit tests"

Tags:

java

sonarqube

Does anybody knows about this issue “Insufficient branch coverage by unit tests”? My class code coverage is 99% but I am keep getting sonar warning for that same class “Insufficient branch coverage by unit tests : 111 more branches need to be covered by unit tests to reach the minimum threshold of 65.0% branch coverage.” Normally this error occurred due to Insufficient coverage of if/else condition as we have to handle positive/negative both scenarios. Does anybody knows anything else about this warning?

Thanks Sach

like image 215
sach Avatar asked Aug 19 '15 11:08

sach


1 Answers

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

For instance :

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

if in your tests you always have a that is true, then you are covering the line indeed but not all the branches possible.

Please also watch out for try with resources as this generates a lot of branches in bytecode (and you don't see them in source) and you are most probably not covering all of them.

like image 58
benzonico Avatar answered Nov 05 '22 02:11

benzonico