Break the form
A college form asks for your age. It says: only 16, 17, 18 or 19.
You are the tester. What do you type to find a bug? Try 17. Try 16. Try 20. Try the word "abc".
A good tester picks data on purpose. Today you learn how.
Key words
| Word | What it means | Example |
|---|---|---|
| Test data | The values we give to a program to test it. | 17 |
| Range | The values that are allowed, from a lowest to a highest. The lowest and the highest are the edges of the range. | 16 to 19 |
| Valid data | Data the program should accept. | 17 |
| Invalid data | Data of the right type that the program should refuse, because it is outside the range. | 5 |
| Valid extreme data | Data on the very edge of the range, still allowed. | 16 and 19 |
| Invalid extreme data | Data just outside the edge of the range, not allowed. | 15 and 20 |
| Erroneous data | Data of the wrong type. It is not the kind of thing the program expects, such as a word where a number should be. | "abc" |
| Expected result | What the program should do with that data. | Accept, or show an error |
The cells students fill in are left blank in this preview.
Five kinds of test data
| Kind | Example for age 16 to 19 | Expected result |
|---|---|---|
| Valid (normal) | 17, 18 | Accepted |
| Valid extreme | 16, 19 | Accepted |
| Invalid | 5, 80 | Refused: outside the range |
| Invalid extreme | 15, 20 | Refused: outside the range |
| Erroneous | "abc", empty, 16.5 | Refused: not a whole number |
The cells students fill in are left blank in this preview.
The age range on a line
| 5 | 15 | 16 | 17 | 18 | 19 | 20 | 80 |
|---|---|---|---|---|---|---|---|
| Invalid | Invalid extreme | Valid extreme | Valid (normal) | Valid (normal) | Valid extreme | Invalid extreme | Invalid |
The cells students fill in are left blank in this preview.
Why test the edges?
data-callouts.important.label
Programmers write age >= 16 and age <= 19. Here >= means "bigger than or equal to" and <= means "smaller than or equal to". A small mistake, such as age > 16 (only bigger than 16), refuses a 16 year old. Only the edge value 16 finds this. Testing 17 or 18 never shows the bug.
Try it: run the test data
def check_age(text):
if not text.isdigit():
return "not a number"
age = int(text)
if age < 16 or age > 19:
return "wrong range"
return "ok"
for value in ["17", "16", "19", "15", "20", "abc", "16.5"]:
print(value, "->", check_age(value))
# Change age < 16 to age <= 16. Which test data finds the bug?
# (<= means "smaller than or equal to")
Worked example: a test mark
| Kind | A mark from 0 to 100 | Expected result |
|---|---|---|
| Valid | 55, 80 | Accepted |
| Valid extreme | 0, 100 | Accepted |
| Invalid | -30, 400 | Refused |
| Invalid extreme | -1, 101 | Refused |
| Erroneous | "fifty", empty | Refused: not a number |
The cells students fill in are left blank in this preview.
Four simple steps
For any range, follow four steps.
- Write the lowest and the highest allowed value.
- Valid extreme: those two values.
- Invalid extreme: one less than the lowest, one more than the highest.
- Add a normal value in the middle, and some wrong types.