3

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

user1686342
  • 1,265
  • 1
  • 18
  • 24

1 Answers1

1

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.

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
  • Thanks for your response. Wouldn't two test cases suffice, t1= and t2=? As this would cause both branches to be executed no? Doesn't the above example border onto condition/multi-condition testing? – user1686342 Dec 28 '14 at 19:26
  • 1
    I say this as I am referring to the book "Software Testing and Analysis" by Mauro where I read the following definition for condition testing: "Branch coverage is useful for exercising faults in the way a computation has been decomposed into cases. Condition coverage considers this decomposition in more detail, forcing exploration not only of both possible results of a Boolean expression controlling a branch, but also of different combinations of the individual conditions in a compound Boolean expression." – user1686342 Dec 28 '14 at 19:31
  • You're right, that's condition coverage according to this definition. Modified the answer. – Alex Shesterov Dec 28 '14 at 19:40