Equivalence Partitioning
Previous articles described a good test case
as one that has a reasonable probability of finding an error,
and it also discussed the fact that an exhaustive-input test
of a program is impossible. Hence, in testing a program, you
are limited to trying a small subset of all possible inputs.
Of course, then, you want to select the right subset, the
subset with the highest probability of finding the most
errors.
One way of locating this subset is to realize
that a well-selected test case also should have two other
properties:
- It reduces, by more than a count of one, the number of
other test cases that must be developed to achieve some
predefined goal of "reasonable" testing.
- It covers a large set of other possible test cases. That
is, it tells us something about the presence or absence of
errors over and above this specific set of input values.
These two properties, although they appear to
be similar, describe two distinct considerations. The first
implies that each test case should invoke as many different
input considerations as possible to minimize the total number
of test cases necessary. The second implies that you should
try to partition the input domain of a program into a finite
number of equivalence classes such that you can reasonably
assume (but, of course, not be absolutely sure) that a test of
a representative value of each class is equivalent to a test
of any other value. That is, if one test case in an
equivalence class detects an error, all other test cases in
the equivalence class would be expected to find the same
error. Conversely, if a test case did not detect an error, we
would expect that no other test cases in the equivalence class
would fall within another equivalence class, since equivalence
classes may overlap one another.
These two considerations form a black-box
methodology known as equivalence partitioning. The second
consideration is used to develop a set of "interesting"
conditions to be tested. The first consideration is then used
to develop a minimal set of test cases covering these
conditions.
An example of an equivalence class in the
triangle program of Chapter 1 is the set "three equal-valued
numbers having integer values greater than zero." By
identifying this as an equivalence class, we are stating that
if no error is found by a test of one element of the set, it
is unlikely that an error would be found by a test of another
element of the set. In other words, our testing time is best
spent elsewhere (in different equivalence classes).
Test-case design by equivalence partitioning
proceeds in two steps: (1) identifying the equivalence classes
and (2) defining the test cases. |