Note that, although the same number of test
cases was generated for this example, condition coverage
usually is superior to decision coverage in that it may (but
does not always) cause every individual condition in a
decision to be executed with both outcomes, whereas decision
coverage does not. For instance, in the same branching
statement
DO K=0 to 50 WHILE (J+K>QUEST)
is a two-way branch (execute the loop body or
skip it). If you are using decision testing, the criterion can
be satisfied by letting the loop run from K=0 to 51, without
ever exploring the circumstance where the WHILE clause becomes
false.With the condition criterion, however, a test case would
be needed to generate a false outcome for the conditions
J+K<QUEST.
Although the condition-coverage criterion
appears, at first glance, to satisfy the decision-coverage
criterion, it does not always do so. If the decision IF
(A&B) is being tested, the condition-coverage criterion
would let you write two test cases-A is true, B is false, and
A is false, B is true-but this would not cause the THEN clause
of the IF to execute. The condition-coverage tests for the
earlier example covered all decision outcomes, but this was
only by chance. For instance, two alternative test cases
- A=1, B=0, X=3
- A=2, B=1, X=1
cover all condition outcomes, but they cover
only two of the four decision outcomes (both of them cover
path abe and, hence, do not exercise the true outcome of the
first decision and the false outcome of the second
decision).
The obvious way out of this dilemma is a
criterion called decision/ condition coverage. It requires
sufficient test cases that each condition in a decision takes
on all possible outcomes at least once, each decision takes on
all possible outcomes at least once, and each point of entry
is invoked at least once.
A weakness with decision/condition coverage
is that, although it may appear to exercise all outcomes of
all conditions, it frequently does not because certain
conditions mask other conditions. To see this, examine Figure
2 on next page. The flowchart in Figure 2 is the way a
compiler would generate machine code for the program in Figure
1 on page 2. The multicondition decisions in the source
program have been broken into individual decisions and
branches because most machines do not have a single
instruction that makes multicondition decisions. A more
thorough test coverage, then, appears to be the exercising of
all possible outcomes of each primitive decision. The two
previous decisioncoverage test cases do not accomplish this;
they fail to exercise the false outcome of decision H and the
true outcome of decision K. |