Search code examples
testingbranchcode-coverage

Branch coverage with missing else


Given some code:

int(x) {
 if(x==0) { dosomething }
}

If I run this with two test cases: t1 = <0> and t2 = <2>, will this provide me with 100% branch coverage even though the else statement is missing?

In other words, does the else statement need to exist to achieve 100% branch coverage?

Thanks


Solution

  • Yes, these two inputs will result in full branch coverage. else is not required for full branch coverage.

    You may consider that there's an empty implicit else block.