4.7 Testing and Debugging | 193
divides the integers into three ranges:
1.Integer.MIN_VALUEthrough – 1
- 0 through 100
- 101 through Integer.MAX_VALUE
Thus, we have six values to test. In addition, to verify that the relational operators are cor-
rect, we should test for values of 1 (> 0) and 99 (< 100).
Conditional branches are merely one factor in developing a testing strategy. We con-
sider more of these factors in later chapters.
The Test Plan
We’ve discussed strategies and techniques for testing applications, but how do you approach
the testing of a specific application? You design and implement atest plan—a doc-
ument that specifies the test cases that should be tried, the reason for each test case,
and the expected output. In Chapter 3, we briefly and informally discussed the
idea of a test plan. Now we take a closer look at what makes up a formal test plan.
Implementing a test planinvolves running the application using the data specified by
the test cases in the plan and checking and recording the results.
The test plan should be developed together with the design. The following
table shows a partial test plan for the StudentStatus application. The first test case
involves a passing set of scores. The second test case is a marginal set, and the
third test case is a failing set. The last set checks what happens when we input
invalid data. Our program treats negative values as valid scores and merely
computes an average with them, so in this case the result should be failing. A
Case Study Follow-Up exercise asks you to add a test for invalid data.
Test Plan for the StudentStatusApplication
Reason for Test Case Input Values Expected Output Observed Output
Test passing 70, 80, 90 passing
Test marginal 65, 75, 55 marginally passing
Test failing 45, 55, 65 failing
Test invalid data –10, –10, –10 failing
Implementing a test plan does not guarantee that your code is completely correct. It
means only that a careful, systematic test of the code has not demonstrated any bugs. The
situation shown in Figure 4.8 is analogous to trying to test a program without a plan—de-
pending only on luck, you may completely miss the fact that a program contains numer-
ous errors. Developing and implementing a written test plan, on the other hand, casts a
wide net that is much more likely to find errors.
Test plan A document that
specifies how an application is
to be tested
Test plan implementation
Using the test cases specified in
a test plan to verify that an ap-
plication outputs the predicted
results