Intermediate

Testing Programs

AicademyAicademy
·OCR GCSE Computer Science·OCR J277·8 min
2.3.2 Testing

Why Testing Matters

Testing verifies that a program behaves correctly — that it produces the expected output for all possible inputs, including unusual or invalid ones. Without testing, bugs reach users.

OCR J277 covers two aspects of testing: when to test (iterative vs final), and what data to use.

The purpose of testing:

  • Confirm the program does what it is designed to do
  • Find and fix errors (bugs) before the program is released
  • Ensure the program handles invalid input without crashing
  • Provide evidence that the program meets its specification

A program that works for the developer's test cases but fails for users has not been tested thoroughly. The choice of test data determines what errors are found.

Testing can only show the presence of bugs — it cannot prove a program is entirely bug-free. Thorough testing makes it much less likely that bugs remain.

Iterative and Final Testing

Iterative testing happens during development.

(Extra context — OCR J277 uses the term "iterative testing"; "formative" and "modular" are alternative names used in other contexts but are not required OCR terminology.) Each component or subroutine is tested as soon as it is written, before moving on. Problems are caught and fixed early, when they are cheapest to address.

Final (terminal) testing happens when the complete program is finished. The whole system is tested together to ensure all components integrate correctly.

FeatureIterative testingFinal/terminal testing
WhenDuring development, module by moduleAt the end, on the complete program
What is testedIndividual subroutines or componentsThe full integrated system
When errors are foundEarly — easier and cheaper to fixLate — may require rework across modules
What it catchesBugs in individual componentsIntegration bugs and end-to-end behaviour

Worked example: building a quiz program with three subroutines — displayQuestion, getAnswer, and updateScore. With iterative testing, each subroutine is tested immediately after writing. With final testing only, a bug in getAnswer may not be found until the entire program is assembled.

Most real development uses iterative testing throughout, with final testing as a final check before release.

Syntax Errors and Logic Errors

Two error categories arise in programming:

Syntax error — the code breaks the grammatical rules of the programming language. The translator (compiler or interpreter) cannot parse it and the program will not run.

if score > 50    # missing colon — syntax error
    print("Pass")

Logic error — the code runs without crashing, but produces incorrect or unexpected output because the logic is wrong.

if score > 50:    # should be >= 50 for "pass at 50"
    print("Pass")
else:
    print("Fail")

A student with score exactly 50 would be told "Fail". No crash — just wrong output.

Error typeDetectable byEffect
Syntax errorTranslator (at compile/run time)Program will not run at all
Logic errorTesting with appropriate dataProgram runs but gives wrong results

A syntax error prevents execution. A logic error allows execution but produces wrong answers. You cannot find a logic error by reading the error messages — you find it by testing with carefully chosen data.

Test Data — Normal, Boundary, Invalid and Erroneous

Test data is the set of inputs used to test a program. OCR J277 requires knowledge of four categories:

CategoryDefinitionExample (for age input, valid range 0–120)
NormalValid data that the program should accept without errors25, 47, 100
BoundaryValid data at the very edge of the acceptable range0, 120 (the limits themselves)
InvalidCorrect data type but outside the acceptable range — should be rejected-1, 121
ErroneousWrong data type entirely — should be rejected"hello", 3.5, "" (empty)

Why test at the boundary? Boundary values are where off-by-one errors appear. A check written as age > 120 incorrectly accepts 120; a check written as age >= 120 incorrectly rejects 120. Normal values in the middle don't catch this bug — boundary values do.

Studying this for an exam?

Generate a personalised learning path for this subject. Free to get started.

Create a learning path

Writing a Test Plan

A test plan documents the inputs to be tested, the expected results, and (after testing) the actual results. It provides evidence that systematic testing was carried out.

Worked example — test plan for a program that accepts scores from 0 to 100:

TestTypeInputExpected outputActual outputPass/Fail
1Normal50"Valid score"
2Normal85"Valid score"
3Boundary0"Valid score"
4Boundary100"Valid score"
5Invalid-1"Invalid. Enter 0–100."
6Invalid101"Invalid. Enter 0–100."
7Erroneous"abc"Error or rejection message
8Erroneous45.5Error or rejection message

A complete test plan includes at least one test from each of the four categories. Exam questions often provide a partially completed test plan and ask you to fill in missing entries.

Refining Algorithms

Testing does not just find bugs — it drives algorithm refinement. When a test reveals unexpected output, the algorithm must be revised and re-tested.

Worked example — a sorting algorithm incorrectly handles a list with duplicate values:

Initial test:

  • Input: [3, 1, 2] → Output: [1, 2, 3]
  • Input: [3, 1, 3] → Output: [3, 1, 3] ✗ (duplicates not handled)

The bug is found by testing a case the original developer did not consider. The algorithm is then revised and the test re-run to confirm the fix.

Refined test approach — always include test cases for:

(Extra context — the following edge-case list is good practice but goes beyond the OCR J277 2.3.2 requirement to "identify suitable test data for a given scenario.")

  • Empty inputs (zero items)
  • Lists with duplicate values
  • Lists already in order
  • Lists in reverse order
  • Single-element lists

These represent the edge cases that reveal weaknesses in typical algorithm implementations.

(Extra context — OCR J277 2.3.2 only requires understanding that testing leads to algorithm revision; efficiency and robustness improvements are covered in other spec sections.) Refining algorithms means making them more correct (handles more cases), more efficient (faster or uses less memory), or more robust (handles bad input gracefully).

Common Exam Mistakes

1. Confusing invalid and erroneous test data

Invalid data is the correct type but outside the valid range: for an age field, -1 is an integer (correct type) but invalid. Erroneous data is the wrong type entirely: "hello" is a string, not an integer — erroneous.

2. Forgetting boundary values on both sides

For a range of 0–100, the boundary values are 0 and 100 — both ends. Test both. Students often only test one boundary.

3. Classifying syntax errors as logic errors

If the program will not run, the error is syntax. If it runs but gives wrong output, it is logic. A missing colon in Python is a syntax error; the wrong comparison operator is a logic error.

4. Test plans with only normal data

A test plan that only includes values from the middle of the valid range misses boundary, invalid, and erroneous cases — exactly where bugs are most likely to be. Include all four categories.

MistakeCorrection
Using -1 as "erroneous" data for an age field-1 is invalid (correct type, wrong range); erroneous would be "minus one" or 3.5
Boundary test for range 1–10 uses only 5Boundary values are 1 and 10 — both ends
"Program crashes — that's a logic error"A crash caused by unparseable code is a syntax error

Generate revision on any topic you study

Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set — personalised to your level.

Lessons on anything

Structured, level-matched lessons on any topic you study

Practice quizzes

Find out what you actually know before the exam does

Flashcard sets

Lock in key concepts with instant revision cards

Ask Aica

Stuck on something? Get a clear explanation, any time

Prev

Defensive Design

Next

Boolean Logic

Related lessons

7 Slides

Lesson

Defensive Design

OCR GCSE Computer Science · OCR J277

2 days ago

7 Slides

Lesson

Designing and Refining Algorithms

OCR GCSE Computer Science · OCR J277

2 days ago

8 Slides

Lesson

Sorting Algorithms

OCR GCSE Computer Science · OCR J277

2 days ago