Branch coverage takes into consideration the fact that branching instructions (ifs, fors, whiles, 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.

Figure 3.5 A control-flow graph of the CountWords program


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *