It should be easy to see that a set of test
cases satisfying the multiplecondition criterion also
satisfies the decision-coverage, conditioncoverage, and
decision/condition-coverage criteria.
1. A>1, B=0 |
5. A=2, X>1 |
2. A>1, B<>0 |
6. A=2, X<=1 |
3. A<=1, B=0 |
7. A<>2, X>1 |
4. A<=1, B<>0 |
8. A<>2, X<=1 |
Note, as was the case earlier, that cases 5
through 8 express values at the point of the second if
statement. Since x may be altered above this if statement, the
values needed at this if statement must be backed up through
the logic to find the corresponding input values.
These combinations to be tested do not
necessarily imply that eight test cases are needed. In fact,
they can be covered by four test cases. The test-case input
values, and the combinations they cover, are as follows:
A=2, B=0, X=4 |
Covers 1, 5 |
A=2, B=1, X=1 |
Covers 2, 6 |
A=1, B=0, X=2 |
Covers 3, 7 |
A=1, B=1, X=1 |
Covers 4, 8 |
The fact that there are four test cases and
four distinct paths in Figure 1 is just coincidence. In fact,
these four test cases do not cover every Test-Case Design 51
path; they miss the path acd. For instance, you would need
eight test cases for the following decision:
if(x==y && length(z)==0 && FLAG)
{ j=1; else i=1; }
although it contains only two paths. In the
case of loops, the number of test cases required by the
multiple-condition criterion is normally much less than the
number of paths.
In summary, for programs containing only one
condition per decision, a minimum test criterion is a
sufficient number of test cases to (1) evoke all outcomes of
each decision at least once and (2) invoke each point of entry
(such as entry point or ON-unit) at least once, to ensure that
all statements are executed at least once. For programs
containing decisions having multiple conditions, the minimum
criterion is a sufficient number of test cases to evoke all
possible combinations of condition outcomes in each decision,
and all points of entry to the program, at least once. (The
word "possible" is inserted because some combinations may be
found to be impossible to create.) |