Programming and Problem Solving with Java

(やまだぃちぅ) #1

CASE STUDY


466


Here is the output from running the application on this data file:

9.4 Testing and Debugging


The same testing techniques we used with whileloops apply to doand forloops as well.
There are, however, a few additional considerations with these loops.
The body of a doloop always executes at least once. For this reason, you should try data
sets that show the result of executing a doloop the minimal number of times.
With a data-dependent forloop, it is important to test for proper results when the loop
executes zero times. This situation arises when the starting value is greater than the end-
ing value (or less than the ending value if the loop control variable is being decremented).
When an application contains aswitchstatement, you should test it with enough
different data sets to ensure that each branch is selected and executed correctly. You
should also test the application with a switch expression whose value is not in any of
the case labels.
An application that handles exceptions must be tested to ensure that the exceptions
are generated appropriately and then handled properly. Test cases must be included to
Free download pdf