Testing: validation, verification and test data
IGCSE Computer Science · Algorithm Design and Problem-Solving
Validation and verification are not the same
| validation | an automatic check by the computer that the data entered is reasonable |
| verification | a check that the data entered matches the original source |
The crucial point, and the one most often missed: validation cannot tell whether data is correct — only whether it is sensible.
A date of birth of $\text{14/03/2008}$ passes every validation check that could be written. It is still wrong if the person was born in $2009$. Only verification — comparing against the source document — catches that.
Validation checks
- range check — the value lies between stated limits, for example a mark from $0$ to $100$;
- length check — the data has the right number of characters, for example a password of at least $8$;
- type check — the data is the right data type, for example a number where a number is expected;
- presence check — a required field is not left empty;
- format check — the data follows a pattern, for example two letters then six digits;
- check digit — an extra digit calculated from the others, used on barcodes and account numbers to catch typing errors.
Verification methods
- double entry — the data is typed twice and the computer compares the two versions; a difference means at least one was mistyped;
- visual check — a person reads the data on screen and compares it with the original document.
Note that double entry does not prove the data is correct either: someone can make the same mistake twice, or copy the same wrong source. It only catches typing slips.
The four types of test data
| normal | values inside the accepted range that the program should accept — for a mark out of 100: $45$ |
| abnormal (erroneous) | values the program should reject — $-5$, $150$, or the word "fifty" |
| extreme | the largest and smallest values still accepted — $0$ and $100$ |
| boundary | values on either side of each limit, one accepted and one rejected — $-1$ and $0$; $100$ and $101$ |
Extreme and boundary are the pair most often confused. Extreme data is a single value at each end. Boundary data comes in pairs straddling the limit, and each pair tests a different outcome.
Boundary testing matters because the commonest coding error is writing $>$ where $\geq$ was meant. That error is invisible to normal data and only shows up exactly at the limit.
Trace tables
A trace table records the value of every variable after each step of an algorithm, so the programmer can see where a value first becomes wrong.
It is the standard way to dry-run an algorithm by hand, before or instead of running it.
Types of error
- syntax error — breaks the rules of the language, so the program will not translate; for example a missing bracket;
- logic error — the program runs but gives the wrong answer; for example adding where it should subtract.
Logic errors are far more dangerous, precisely because nothing reports them.
Worked example: validation or verification
A school enters students' dates of birth from birth certificates. (a) State the validation checks that could be used. (b) Explain why validation is still not enough. (c) State two ways to verify the data and their limitations.
Solution
(a) Validation checks that could be used.
- format check — the date of birth must follow the pattern $\text{DD/MM/YYYY}$;
- range check — the month must be from $1$ to $12$; the day must be from $1$ to $31$; the year must be sensible for a student's age;
- type check — all three parts must be numbers;
- presence check — the date of birth field must not be left empty.
(b) Why validation is still not enough.
Validation can only answer the question “is this data reasonable?” It can never answer the question “is this data correct?”
A concrete example. A staff member types $\text{14/03/2008}$ while the birth certificate says $\text{14/03/2009}$.
This value passes every check in part (a): correct format, month and day within range, all numbers, not empty. The computer has no way of knowing it is wrong.
The root reason: the computer cannot see the birth certificate. It only has what was typed in, so it can only check whether that is reasonable in itself.
To detect a discrepancy from the original, there must be a comparison with the original — and that is precisely verification.
(c) Two ways to verify and their limitations.
Method one — double entry. The data is typed in twice, usually by two people, and the computer compares the two versions. A difference means at least one version was mistyped, and the computer asks for re-entry.
Limitation: it does not prove the data is correct. Two people can make the same mistake, or both misread the same badly written digit on the paper. It also doubles the data-entry time.
Method two — visual check. A person reads the data on screen and compares each field with the original document.
Limitation: it depends on human concentration. When checking hundreds of similar records, the checker misses things — and the longer they check, the more they miss.
Conclusion: no check is absolutely guaranteed. The practical approach is to use both: validation blocks unreasonable data, verification catches copying mistakes.
Worked example: choosing the four types of test data
A program accepts only marks from $0$ to $100$. Give an example for each type of test data, state the expected result, and explain why boundary data catches a fault that normal data does not.
Solution
Normal data. Examples: $45$, $72$.
Expected result: the program accepts them and processes them normally.
Purpose: to check that the program does its main job correctly with ordinary input.
Abnormal data. Examples: $-5$, $150$, and the word “fifty”.
Expected result: the program rejects them and shows a clear error message.
Note the third example: it tests the type check, that is, whether the program copes when the user types letters into a numeric field. Many programs crash at exactly this point.
Extreme data. Examples: $0$ and $100$.
Expected result: the program accepts both.
These are the largest and smallest values that are still valid — one value at each end.
Boundary data. Examples: the pair $(-1, 0)$ and the pair $(100, 101)$.
Expected result: $-1$ is rejected but $0$ is accepted; $100$ is accepted but $101$ is rejected.
Note that boundary data comes as a pair, and each pair tests two opposite results sitting side by side.
Why boundary data catches a fault that normal data does not.
The most common programming error here is writing a greater-than sign when the intention was greater than or equal to.
Specifically. Suppose the programmer writes the acceptance condition as $\text{mark} > 0$ and $\text{mark} < 100$, when it should be $\text{mark} \ge 0$ and $\text{mark} \le 100$.
This faulty program works perfectly normally with $45$, with $72$, with every value in between. Nothing shows up at all.
It goes wrong at exactly two values: it rejects $0$ and rejects $100$, even though both are valid.
In other words, this fault only shows up right at the limit. Without boundary testing the fault slips into the product, and is only discovered when a real student scores exactly $0$ or exactly $100$.