Validation and Testing · Cambridge syllabus 7.5, 7.6, 7.7, 7.8 · Lesson 2 of 3
Testing
A test plan gives inputs and expected results before running a program. Use normal data, abnormal data that should be rejected, extreme data (the largest and smallest acceptable values) and boundary data (each extreme and the value just beyond it). Check both sides of each boundary to expose incorrect comparisons.
By the end, you can
- Understand the purpose of testing.
- Use normal data.
- Use boundary data.
- Use abnormal data.
- Predict expected results.
- Use extreme data.
- Identify the largest and smallest acceptable values.
- Identify the corresponding rejected values.
- Construct boundary test cases.
- Explain why boundary values are important.
Test data
Testing is running a program with chosen data to find out whether it does what it should. A program that has only been tried once, with a value that happened to work, has not been tested.
A test plan is a table of test cases written before the test is run. Each row gives the data, the reason for choosing it, the result expected, and — after running — the result actually obtained. Writing the expected result first is what makes it a test rather than an observation: otherwise it is too easy to see the output and decide it looks about right.
Normal data is data a user would typically enter and that should be accepted and processed correctly. For a percentage mark, 45 or 78. The purpose is to check that the program works in ordinary use.
Abnormal data is data the program should reject: text where a number is expected, a mark of 150 or −5, an empty entry. The purpose is to check that the program rejects it with a message, instead of crashing or storing it.
Extreme data is the largest and smallest values that are still acceptable — 0 and 100 for a percentage — and it is tested because the ends of a range are where mistakes live. Choosing test data well means choosing a few values that each test something different, rather than many that test the same thing.
Worth remembering
- Write the expected result before running the test, or it is not a test.
- Normal data should be accepted; abnormal data should be rejected with a message.
- Extreme data is the largest and smallest values still acceptable.
Boundary testing
Boundary data is the pair of values either side of the edge of an acceptable range: the last value accepted and the first value rejected. For a mark out of 100 the boundaries are 0 and −1 at the bottom, and 100 and 101 at the top.
These matter more than any other test data because the edge is exactly where the commonest programming error lives. Writing IF Mark > 0 instead of IF Mark >= 0 rejects a legitimate mark of zero, and nothing but a test at zero will reveal it. Errors of this kind pass every test with ordinary values.
Constructing the cases is mechanical. Find the minimum and maximum of the valid range; test the minimum and the value one below it; test the maximum and the value one above it. Four values check both ends in both directions.
The correct expected results must be written down for all four: minimum accepted, one below rejected, maximum accepted, one above rejected. A test where the value is accepted but should not be is as much a failure as a crash.
Where the value is not a whole number, the value just outside is whatever the precision allows — for a range up to 100.0 recorded to one decimal place, 100.1 rather than 101.
Worth remembering
- Boundary data is the last value accepted and the first value rejected.
- Off-by-one errors such as > instead of >= only show up at the boundary.
- Test the minimum, one below, the maximum and one above.
Worked example
For accepted marks 0–100: normal 50; abnormal −20 or "ten"; extreme 0 and 100; boundary 0 and −1, 100 and 101.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
10 and 20 should be accepted; 9 and 21 should be rejected.
Check your method, units and explanation against it.
Marked practice
Set 1 of 5 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.