Testing means running a program on chosen inputs and comparing the actual result with the expected one. Three kinds of input do the work: normal, boundary and invalid.
This lesson is part of problem solving and algorithms. Once you understand the three types, the deeper lesson on choosing test data from one specification shows how to build a full plan.
What are the three types?
| Type | Meaning | Example for marks from 0 to 100 |
|---|---|---|
| Normal | Typical valid value | 65 |
| Boundary | On the edge of the range, plus the first value outside | 0, 100, and −1 and 101 |
| Invalid | Wrong kind of data, expected to be rejected | “abc” or 72.5 |
Normal data proves the program works in the usual case. Boundary data proves the edges are coded exactly. Invalid data proves the program protects itself.
Worked example: a grading program
The rule is: a mark of 40 or more is a Pass, otherwise a Fail. Marks are whole numbers from 0 to 100.
A student writes:
INPUT mark
IF mark > 40 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
END IF
Test with a normal value, 65. Expected: Pass. Actual: Pass. The student stops here and believes the program is correct.
What does the boundary test show?
Now test 40, the lowest mark that should pass. Expected: Pass. Actual: 40 > 40 is false, so the program outputs Fail.
| Input | Expected | Actual | Result |
|---|---|---|---|
| 65 | Pass | Pass | Matches |
| 40 | Pass | Fail | Fault found |
| 39 | Fail | Fail | Matches |
The repair is one character: change > to >=. The table also shows why 39 belongs in the plan, because it checks that the fix did not let failing marks through.
What mistake should you avoid?
The mistake is to decide that a program is tested because it worked once. A single normal value tests one path out of several, and it cannot test the edge at all.
A better habit is to write three rows before you run anything: one normal, the two boundaries with their neighbours, and one invalid. Then fill in the actual column only after running.
Check yourself
A school fridge alarm should sound when the temperature is above 8 °C. The sensor reports whole numbers from −10 to 30. Choose at least five tests and say what each should do.
Answer
Normal: 5, no alarm. Boundary on the rule: 8, no alarm (not above 8), and 9, alarm. Edges of the sensor range: −10 and 30, both valid, with 30 sounding the alarm. Invalid: 31 or “hot”, which the program should reject.
The pair 8 and 9 is the key test, because it separates > from >=.
What to study next
Practise all four skills in this section with the problem solving and algorithms practice set. Keep a record of the test cases you forget using the mistake log and paper-error review.
If you want a teacher to go through your own test plans, see online one-to-one Computer Science tuition.