Condition + branch coverage considers not only possible branches but also each condition of each branch statement. For example, the first if statement in the CountWords program contains three conditions: !Character.isLetter(str.charAt(i))last == 's', and last == 'r'. Therefore, a developer aiming for condition + branch coverage should create a test suite that exercises each of those individual conditions being evaluated to true and false at least once and the entire branch statement being true and false at least once.

Note that blindly looking only at the conditions (and ignoring how they are combined) may result in test suites that do not cover everything. Imagine a simple if(A || B). A test suite composed of two tests (T1 that makes A true and B false and T2 that makes A false and B true) covers the two conditions, as each condition is exercised as true and false. However, the test suite does not fully cover the branch, as in both tests, the evaluation of the entire if statement is always true. This is why we use condition + branch coverage, and not only (basic) condition coverage.

In the extended CFG in figure 3.6, branch nodes contain only a single condition. The complicated if is broken into three nodes.

Figure 3.6 The extended control-flow graph of the CountWords program. Each condition is in its own node. Covering all the edges in the graph means achieving 100% condition + branch coverage.


Comments

Leave a Reply

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