GoalChoose normal, boundary and invalid test data, and use boundary data to find a < or <= mistake.
New words
normal data · ordinary values that the program should acceptboundary data · values at the edge of the allowed range, and the values just outside itinvalid data · data the program should reject, such as the wrong type or a value that makes no sense
Explanation
A good test uses more than one kind of data. Normal data is an everyday value that should work, such as 4 people in a lift. Boundary data sits on the edge of what is allowed, for example 1 and 8 if the lift holds 1 to 8 people. We also test the values just outside, which are 0 and 9. Invalid data should be rejected, for example the word six where a number is expected, or the number 20. Many mistakes hide at the boundary. Writing < when you meant <= is a logic error, and the program still runs, but it gives the wrong answer for one value. Only a boundary test finds it. A normal test of 4 would pass both versions.
Kind of data
Lift allows 1 to 8 people
Why
normal
4
well inside the range
boundary
1, 8 (and 0, 9 outside)
on or next to the edges
invalid
six, or 20
wrong type or impossible
Worked examples
Python
1people = int(input("People? "))
2if people >= 1and people <= 8:
3print("Lift OK")
4else:
5print("Not allowed")
Output
Lift OK
A lift program for 1 to 8 people. The condition uses >= and <=, so both ends are allowed. With 8 typed, the first test is true.
Type
Test data
Expected outcome
normal
4
Lift OK
boundary
1
Lift OK
boundary
8
Lift OK
boundary
0
Not allowed
boundary
9
Not allowed
invalid
six
message, not a crash
A test plan for it. The expected outcome was worked out by hand before running. Three kinds of data are used, and the boundary values are on both sides of each edge.
Python
1people = int(input("People? "))
2if people >= 1and people < 8:
3print("Lift OK")
4else:
5print("Not allowed")
Output
Not allowed
A buggy version. It uses people < 8, so exactly 8 people are wrongly refused. The normal test with 4 passes, and the test with 7 passes. Only the boundary test with 8 finds the bug.
Class activity
Sorting test cards (no computer). A swimming pool has lanes that can take 2 to 6 swimmers. Write these numbers on cards: 4, 2, 6, 1, 7, 3, 12 and the word four. Sort the cards into three piles: normal, boundary (on the edge or just outside), and invalid. Decide what the program should do for each card. Then write the three missing test cards for a different rule: a lift taking 3 to 10 people. If you have a computer or tablet, ask an adult to help you run the lane program with a few of the numbers.
Practice
1
A program accepts quiz scores from 0 to 20. List one normal value, the boundary values, and one invalid value.
Normal: 12. Boundary: 0 and 20, and the values just outside, −1 and 21. Invalid: the word “ten”, or 50.
2
The program sets a lane open when lane >= 2 and lane <= 6. Complete the table.
Type
Test data
Expected outcome
?
4
?
?
2
?
?
7
?
4 is normal data and gives Lane open. 2 is boundary data (on the edge) and gives Lane open. 7 is boundary data just outside the range and gives Lane closed.
3
A pupil writes lane > 2 and lane <= 6. Which test value finds the mistake, and what would the program print for it?
Python
1lane = int(input("Swimmers? "))
2if lane > 2and lane <= 6:
3print("Lane open")
4else:
5print("Lane closed")
Test value 2. It should print Lane open, but with > 2 the program prints Lane closed. This is a logic error found by boundary data.
4
Why is testing only the number 4 not enough for the lift program?
4 is normal data, so it passes even when the edges are wrong. Boundary data and invalid data are needed to find the mistakes at the edges and with wrong input.