Posts Tagged branch coverage

Misapprehension 13: Branch coverage subsumes statement coverage, therefore you can conclude 50% statement coverage from 50% branch coverage

Branch coverage actually subsumes statement coverage, i.e. you can conclude 100% statement coverage from 100% branch coverage. But you cannot conclude 50% statement coverage from 50% branch coverage. See the figure below for an example.

Can you conclude 50% statement coverage from 50% branch coverage?

Can you conclude 50% statement coverage from 50% branch coverage?

If you execute an arbitrary test case for the code snippet in the figure above, you will get 50% branch coverage, but you will not get 50% statement coverage, because the two branches that are present contain a different number of statements each.

, , ,

No Comments

Misapprehension 1: 100% can always be reached

Of course not. It is easy to find real-world examples where the structure of the code prevents the software from being executed completely.

Branch Coverage

Figure: An example where 100% branch coverage cannot be reached

The figure above designates a software snippet where 100% branch coverage cannot be reached. This is a real-world example that was simplified.
Why can 100% not be reached? The cause is the missing execution of the “default:” case of the switch instruction. This “default:” case is always present, whether it is programmed explicitly or not.


, , ,

No Comments