OCR J277 · Component 02 · §2.3 · Paper 2

§2.3 Producing Robust Programs

How do you design programs that handle unexpected inputs — and how do you verify they actually work?

Robust programs anticipate misuse. A user will enter text where a number was expected, leave fields blank, type a negative value for age, or try to log in with someone else's credentials. Defensive design builds in checks before these inputs can cause harm — input validation rejects data that doesn't meet the rules; authentication verifies the user is who they claim to be. These are programming decisions made at design time, not patches added later.

Testing verifies that a program actually does what it is supposed to. OCR's distinction between normal (valid), boundary (at the edge of valid), invalid (correct type but outside range), and erroneous (wrong type entirely) test data is a key discriminator in the exam. A test table shows input → expected output → actual output → pass/fail. Iterative testing happens throughout development; final/terminal testing happens at the end. The difference between a syntax error (the code doesn't run) and a logic error (the code runs but gives the wrong answer) maps directly to different types of testing tool.

A program accepts a student's exam score as an integer between 0 and 100. Design a test table with at least six test cases covering all four data types (normal, boundary, invalid, erroneous). For each: state the input, the expected output, and the type of test data.

Test data types — the four-way OCR distinction

Normal: valid input within the accepted range (e.g. score = 65) — should be accepted
Boundary: at the edge of the accepted range (e.g. score = 0 or score = 100) — accepted; tests the limit
Invalid: correct type but outside the accepted range (e.g. score = −5 or score = 150) — should be rejected with error message
Erroneous: wrong data type entirely (e.g. score = "fifty") — should be rejected; program should not crash

What students must understand

Diagrams

Two circles labelled Code and Test joined by arrows in a loop
Iterative testing. Code and test alternate in a loop all the way through development.
A reCAPTCHA checkbox reading I'm not a robot
Authentication in defensive design. A CAPTCHA checks the user is human before input is accepted.

Diagrams: PG Online (Paul Long), OCR J277 textbook. Used under the school site licence.

Linking questions

Practice

Video Support

Craig'n'Dave — OCR J277
2.3 Producing robust programs — unit playlist