Robust programs: validation and testing
Users type the strangest things: their age as 150, a blank name, or a word where a number should be. A robust program checks its input and is tested before anyone uses it.
Validation checks
| Check | What it checks | Example |
|---|---|---|
| Range check | a number is between limits | age is from 11 to 16 |
| Presence check | something has been entered | name is not blank |
| Length check | the number of characters | a password has at least 8 characters |
| Type check | the data is the right type | age is a whole number |
| Format check | the data follows a pattern | a date is written dd/mm/yyyy |
Validation in Python
age = int(input("Age (11 to 16)? "))
while age < 11 or age > 16:
print("Not valid, try again")
age = int(input("Age (11 to 16)? "))
print("Thanks, age", age)
If the user types 20, then 9, then 14, the messages printed (as well as the prompts) are:
Not valid, try again
Not valid, try again
Thanks, age 14
This is a range check. Using len(name) == 0 instead would be a presence check.
Testing with test data
| Type | Meaning | Examples | Should it be accepted? |
|---|---|---|---|
| Normal | typical data that should be accepted | 13, 14 | yes |
| Boundary | values at the edges of the allowed range | 11 and 16 (and just outside: 10, 17) | 11, 16 yes; 10, 17 no |
| Erroneous | data that should be rejected | 50, -3, "twelve" | no |
A program asks for a test mark from 0 to 50. Give one normal, one boundary and one erroneous test value, and say what should happen.
- Normal: 30, which should be accepted.
- Boundary: 50, the top edge, which should be accepted (51 should be rejected).
- Erroneous: 75 or a word such as "ten", which should be rejected with a message.
Answer: For example: 30 (accept), 50 (accept), 75 (reject).
Validation checks input is sensible before it is used: range, presence, length, type and format checks. Test with normal, boundary and erroneous data to prove the program copes with anything.
- AND
- A Boolean operator that gives True (1) only when both inputs are True.
- Program
- A set of instructions written in a programming language that a computer can run.
- Input
- Data put into a computer, for example from a keyboard, mouse, microphone or sensor.
- While loop
- A condition-controlled loop that repeats while its condition is True.
- NOT
- A Boolean operator that flips its input: True becomes False and False becomes True.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
A form will not let you leave the surname box blank. Which check is this?
- Length check
- Range check
- Type check
- Presence check
Show the answer
Answer: Presence check
Something must be entered.
A username must be no more than 12 characters. Which check is this?
- Range check
- Length check
- Presence check
- Format check
Show the answer
Answer: Length check
Counting characters is a length check.
Check you have got it
Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.
Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.