Whenever we identify a line of code that is not covered, we have to decide how thorough (or rigorous) we want to be when covering that line. Let’s revisit an if statement from the CountWords program.

Listing 3.4 An if expression from the CountWords program

if (!Character.isLetter(str.charAt(i)) &&
 (last == 's' || last == 'r'))

A developer may decide to only cover the line —in other words, if a test passes through that if line, the developer will consider it covered. A single test case can do this. A slightly more thorough developer may cover the if being evaluated to true and false; doing so requires two test cases. A third developer may explore each condition in the if statement. This particular if has three conditions requiring at least two tests each, for a total of six tests. Finally, a very thorough tester may decide to cover every possible execution path of this statement. Given that it has three different conditions, doing so requires 2 × 2 × 2 = 8 test cases.

Let’s formalize this discussion. Note that you’ve already seen some of these terms.


Comments

Leave a Reply

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