Testing & Defensive Design

J277 · 2.3 Producing Robust Programs · GCSE Computer Science

Component 02

Test Data Types

Scenario: A program accepts a student age between 11 and 18.

Normal Data

Typical valid values that the program should accept and process correctly.

14 ✓

16 ✓

13 ✓

Boundary Data

Values at the extreme edges of the valid range — should be accepted (or just rejected).

11 ✓ (lower boundary)

18 ✓ (upper boundary)

10 ✗ (just outside)

19 ✗ (just outside)

Erroneous Data

Invalid data that the program should reject — wrong type, format, or wildly out of range.

"hello" ✗ (wrong type)

-5 ✗ (negative)

999 ✗ (out of range)

12.5 ✗ (wrong type)

Types of Programming Error

Syntax Error

Breaks the rules of the language. The program cannot run at all.

pritn("Hello")
# Misspelled keyword

Detected by: compiler/interpreter before execution.

Logic Error

Program runs but produces wrong results. The algorithm is incorrect.

average = total + count
# Should be: total / count

Detected by: testing with known inputs/outputs.

Runtime Error

Program starts but crashes during execution. An impossible operation occurs.

x = 10 / 0
# Division by zero error

Detected by: running the program with edge-case inputs.

Defensive Design Techniques

Input Validation

Checking data meets expected criteria before processing. Types: range check (within limits), type check (correct data type), length check (correct number of characters), presence check (field not empty), format check (matches expected pattern e.g. postcode).

Authentication

Verifying a user's identity before granting access. Examples: username/password, security questions, biometrics, two-factor authentication.

Maintainability

Writing code that is easy to understand and modify: meaningful variable names, comments explaining complex logic, consistent indentation, modular design (using subroutines/functions).

Test Data Classifier

Scenario: A program accepts a score between 0 and 100 (inclusive).

Classify each test value as Normal, Boundary, or Erroneous.