Branch coverage takes into consideration the fact that branching instructions (if
s, for
s, while
s, and so on) make the program behave in different ways, depending how the instruction is evaluated. For a simple if(a
&&
b)
statement, having a test case T1 that makes the if
statement true
and another test case T2 that makes the statement false
is enough to consider the branch covered.
Figure 3.5 illustrates a control-flow graph (CFG) of the CountWords
program. You can see that for each if
instruction, two edges come out of the node: one representing where the flow goes if the statement is evaluated to true
and another representing where the program goes if the statement is evaluated to false
. Covering all the edges in the graph means achieving 100% branch coverage.
Leave a Reply