Testing and debugging properly

Computer Science · GCSE · The School

Three kinds of test data

NORMAL data is what you expect (age 25). BOUNDARY data sits at the edges (0, 1, 17, 18 for an adult check) — this is where most bugs live. ERRONEOUS data is what should be rejected ("banana" as an age). A test plan without boundary data misses the very cases that break real programs.

Three kinds of error

SYNTAX errors break the rules of the language and stop it running — the easiest kind, because the computer tells you. RUNTIME errors crash it mid-way (dividing by zero). LOGIC errors are the dangerous ones: the program runs happily and produces the WRONG answer, and only testing finds them.

Debug by halving

Do not guess. Find an input that fails, then narrow: print values halfway through and see whether they are already wrong — that halves the suspect region each time. Change ONE thing, re-test, and keep a note of what you tried. Systematic beats clever, especially at 2am.

The box should accept an age between 0 and 120. NORMAL: 25 — accepted. BOUNDARY: 0 accepted, 120 accepted, −1 rejected, 121 rejected. Those four are where the off-by-one errors live. ERRONEOUS: "twenty", an empty box, 25.5, a 3,000-character string — all rejected without crashing. Testing only 25 tells you almost nothing; the boundaries and the rubbish are where programs actually break.

The School — all subjects · Knowledge map