GCSE Computer Science revision

Robust Programming & Testing

Defensive design, testing, debugging and writing reliable code.

What you will learn

  • Defensive design
  • Testing
  • Types of error
  • Debugging
  • Writing maintainable code

Defensive design

Defensive design anticipates mistakes and bad input. It checks data before using it and fails safely rather than crashing.

  • Input validation checks data is sensible
  • Range checks: numbers within limits
  • Presence checks: a field is not empty
  • Authentication confirms who the user is

Testing

Testing finds errors before users do. Different tests check different things: normal, extreme and exceptional inputs.

  • Normal data: typical, expected inputs
  • Extreme data: at the edge of acceptable values
  • Exceptional data: wrong or unexpected inputs
  • Test plans record inputs, expected and actual results

Types of error

Syntax errors stop code running (e.g. a missing bracket). Logic errors let it run but produce wrong results (e.g. using + instead of −).

  • Syntax error: code won't run (e.g. typo, missing bracket)
  • Logic error: runs but gives wrong output
  • Runtime error: crashes while running (e.g. divide by zero)
  • Trace tables help find logic errors

Debugging

Debugging is finding and fixing errors. Tools include print statements, trace tables, stepping through code and using a debugger.

  • Print variables to see their values
  • Trace tables track each step
  • Step through code line by line
  • A debugger pauses execution to inspect state

Writing maintainable code

Maintainable code is easy to read, change and fix. Use meaningful names, comments, indentation and modular functions.

  • Use meaningful variable and function names
  • Add comments to explain tricky logic
  • Indent code consistently
  • Break programs into reusable functions

Worked answers

  1. 1. A presence check verifies that…

    Answer: A field is not left empty

    Why: It ensures required data has been entered.

    Wrong options to rule out: A number is in range; A password is strong; A date is real

  2. 2. Testing with an input at the very edge of acceptable values is called…

    Answer: Extreme data testing

    Why: Extreme data is at the boundary of what the program accepts.

    Wrong options to rule out: Normal testing; Exceptional testing; Stress testing

  3. 3. A logic error is when the program…

    Answer: Runs but gives the wrong result

    Why: The code is valid but the logic is wrong.

    Wrong options to rule out: Won't run at all; Crashes immediately; Has no comments

Practice questions

Answer from memory first. Pick an option to check it and read the explanation.

1. A missing bracket is an example of a… error.

2. A trace table is used to…

3. Which makes code most maintainable?

4. Dividing by zero causes a… error.

5. Input validation is an example of…

Practise Robust Programming & Testing until it sticks

  • Your answers are saved, so you can see what you actually know
  • Questions you got wrong come back just before you forget them
  • A daily streak and a progress view for every topic
Practise this topic

Free to start. No card needed.

Related GCSE Computer Science topics

Back to all GCSE Computer Science topics. StudyVector is independent and is not endorsed by any exam board, so check this topic against your own specification.