OCR J277 Sub-topic 2.3.2

Testing & Robustness: The Complete Guide

From basic definitions to advanced test plans. Master how to make code "break-proof".

Learning Checklist

Your Progress:
0/6
Click to view full objective list
1

Purpose & Types of Testing

Real-World Analogy: Building a Car

Imagine building a car. You don't just build the whole thing and hope it starts!

  • Purpose: We test to ensure the brakes work (Requirements) and the engine doesn't explode (Robustness).
  • Iterative: The mechanic tests the engine while it is sitting on the bench, before putting it in the car.
  • Final: The test driver takes the finished car on the track to see if everything works together.

Iterative Testing

Testing modules or small chunks of code during development.

Who? The Programmer.
When? During coding.

Final (Terminal) Testing

Testing the complete program at the end of production before release.

Who? Beta testers / Users.
When? At the end.

Checkpoint: Purpose & Types

2

Syntax vs. Logic Errors

Syntax Error

Breaks the grammar rules of the language. The program will not run.

print("Hello" <-- Missing bracket

Logic Error

Code follows rules but design is flawed. Runs but gives unexpected output.

if age > 18: <-- Should be >=
3

Test Data Types

Scenario: A roller coaster ride. Height must be between 120cm and 200cm inclusive.

Visualizing the Logic
Invalid
119
Boundary
120
Normal
150
Boundary
200
Invalid
201
Erroneous: "Dave", "One Hundred" (Wrong Data Type entirely)
1. Normal Data
Data that is within the range and should be accepted. Ex: 150.
2. Boundary Data
Data on the edge of acceptability. Used to check for "Off-by-one" errors. Ex: 120, 200.
3. Invalid Data
Correct Type, but Wrong Value. Ex: 119, 201.

Checkpoint: Data

4

Refining Algorithms

Refining means taking code that has errors (found during testing) and fixing it to make it Robust.

Before (Buggy)

if age > 18:
  print("Adult")

Refined (Robust)

if age >= 18:
  print("Adult")

Lesson Summary & Review