7.6 Test data

← Topic 7.5 Validation and verificationComputer Science contentsTopic 7.7 Trace tables to document dry runs of algorithms →
Chapter 7 · Algorithm design and problem solving

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.

Normal dataAbnormal dataExtreme dataBoundary dataExpected results

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.

Expected result and actual result: before carrying out a test, decide what the result should be. After the algorithm or program is run, compare the actual result with the expected result. If they match, that test has behaved as expected.

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 typeTest dataExpected result
Normal50, 50, 50, 50, 50, 50, 50, 50, 50, 50Average = 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 dataWhy it is abnormalExpected result
-12Outside the permitted percentage rangeRejected
elevenNot a whole-number percentage markRejected
Check normal and abnormal test data.

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 valueExpected result
0Accepted
100Accepted

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

BoundaryTest dataExpected results
Lower boundary-1 and 0-1 rejected; 0 accepted
Upper boundary100 and 101100 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.

Do not confuse extreme and boundary data: extreme values are the smallest and largest valid values. Boundary testing includes values on both sides of a limit so that acceptance and rejection can both be checked.
Check extreme and boundary data.

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.

TypeExample for 0–20 inclusiveExpected result
Normal7, 12, 18Accepted
Abnormal / erroneous-5, 26, "ten"Rejected
Extreme0, 20Accepted
Boundary-1/0 and 20/21-1 and 21 rejected; 0 and 20 accepted

Topic 7.6 revision checklist

Explain why algorithms, programs and sub-systems need to be tested.
Define a set of test data.
Compare expected results with actual results.
Define and suggest normal test data.
Define and suggest abnormal or erroneous test data.
Define and suggest extreme test data.
Define and suggest boundary test data.
Explain the difference between extreme and boundary data.
State whether each test value should be accepted or rejected.
Select more than one type of test data to test a solution thoroughly.
Ready for a mixed Topic 7.6 check?
← Topic 7.5 Validation and verificationComputer Science contentsTopic 7.7 Trace tables to document dry runs of algorithms →