Java Reference
In-Depth Information
unusual input and is incensed when the program misbehaves. The remedy is to ensure
that each part of the code is covered by some test case.
Test coverage is a measure of how many parts of a program have been tested.
For example, in testing the getTax method of the TaxReturn class, you want to
make sure that every if statement is entered for at least one test case. You should test
both single and married taxpayers, with incomes in each of the three tax brackets.
When you select test cases, you should make it a habit to include boundary test cases:
legal values that lie at the boundary of the set of acceptable inputs.
212
213
For example, what happens when you compute the taxes for an income of 0 or if a
bank account has an interest rate of 0%? Boundary cases are still legitimate inputs,
and you expect that the program will handle them correctlyȌoften in some trivial
way or through special cases. Testing boundary cases is important, because
programmers often make mistakes dealing with boundary conditions. Division by
zero, extracting characters from empty strings, and accessing null pointers are
common symptoms of boundary errors.
Boundary test cases are test cases that are at the boundary of acceptable inputs.
S ELF C HECK
9.
How many test cases do you need to cover all branches of the
getDescription method of the Earthquake class?
10. Give a boundary test case for the EarthquakeRunner program.
What output do you expect?
Q UALITY T IP 5.3: Calculate Sample Data Manually
It is usually difficult or impossible to prove that a given program functions
correctly in all cases. For gaining confidence in the correctness of a program, or
for understanding why it does not function as it should, manually calculated
sample data are invaluable. If the program arrives at the same results as the manual
Search WWH ::




Custom Search