7.6 Test data
Testing is used to determine whether an algorithm or program behaves as intended. A solution should be tested with carefully chosen data so that it can be shown to accept valid inputs, reject unsuitable inputs and behave correctly at the limits of an allowed range.
7.6.1 How to suggest and apply suitable test data
Before a whole computer system is tested, individual sub-systems are usually tested separately. An algorithm written as pseudocode or a flowchart can be tested by working through it manually with chosen data. A computer program can be tested by running it using chosen data and checking the output.
A solution normally needs to be tested more than once using different sets of data. A set of test data means all the data items needed to work through one test of the solution.
Normal test data
Normal data is data that the solution would normally be expected to accept and process. It is used to show that the solution does what it is supposed to do for ordinary valid inputs.
Example: average of ten percentage marks
Suppose an algorithm records ten whole-number percentage marks and calculates their average.
| Test type | Test data | Expected result |
|---|---|---|
| Normal | 50, 50, 50, 50, 50, 50, 50, 50, 50, 50 | Average = 50 |
All ten values are valid percentage marks, so the algorithm should accept them and calculate the expected average.
Abnormal / erroneous test data
Abnormal data, also called erroneous data, is data that should be rejected if the solution is working correctly. It is chosen deliberately to prove that the solution does not accept invalid input.
Examples for percentage marks
| Test data | Why it is abnormal | Expected result |
|---|---|---|
| -12 | Outside the permitted percentage range | Rejected |
| eleven | Not a whole-number percentage mark | Rejected |
Extreme test data
Extreme data consists of the largest and smallest values that are still valid normal data. For percentage marks restricted to whole numbers from 0 to 100 inclusive, the extreme values are:
| Extreme value | Expected result |
|---|---|
| 0 | Accepted |
| 100 | Accepted |
Extreme values are still valid values. They test the legal limits of the range.
Boundary test data
Boundary data is used to establish exactly where valid and invalid data meet. At each boundary, two nearby values are tested: one should be accepted and the other should be rejected.
Percentage range 0 to 100 inclusive
| Boundary | Test data | Expected results |
|---|---|---|
| Lower boundary | -1 and 0 | -1 rejected; 0 accepted |
| Upper boundary | 100 and 101 | 100 accepted; 101 rejected |
The lower pair checks the change from invalid to valid at 0. The upper pair checks the change from valid to invalid after 100.
Choosing a complete set of tests
Good testing should not rely on only one type of data. For a range such as 0 to 20 inclusive, useful tests would include ordinary values inside the range, invalid values, the valid extremes, and values just outside the boundaries.
| Type | Example for 0–20 inclusive | Expected result |
|---|---|---|
| Normal | 7, 12, 18 | Accepted |
| Abnormal / erroneous | -5, 26, "ten" | Rejected |
| Extreme | 0, 20 | Accepted |
| Boundary | -1/0 and 20/21 | -1 and 21 rejected; 0 and 20 accepted |