WeLearn

Grade 12 Information Technology · Lesson 6.4

Testing and Debugging Programs

Unit 6: Fundamentals of Programming

Testing checks whether a program works correctly; debugging is finding and fixing the errors (bugs) that testing reveals. Programs can contain three kinds of errors. Syntax errors break the language rules (a missing colon or bracket), so the program will not start. Runtime errors occur while the program runs, such as dividing by zero (ZeroDivisionError), using an undefined variable (NameError) or converting 'abc' to a number (ValueError). Logic errors let the program run but produce wrong results, for example using > instead of >=.

Key terms

Bug
an error in a program
Debugging
finding and fixing bugs
Syntax error
breaking the language's rules
Runtime error
an error that occurs while running
Logic error
the program runs but gives wrong results
Boundary data
test values at the edges of valid ranges
Breakpoint
a point where a debugger pauses execution
Exception handling
using try/except to deal with errors
All Grade 12 Information Technology key terms →

Summary

  • Three error types: syntax, runtime, logic.
  • Test with normal, boundary and invalid data; compare expected and actual output.
  • Debug with tracebacks, print statements, trace tables and breakpoints.
  • Use try/except and validation to handle errors gracefully.

In everyday life: Before Ethiopian banks launch a new mobile app feature, testers try normal, boundary and invalid inputs so customers' money is not affected by bugs.

Check yourself

  • Which type of error is a missing colon after an if statement?
  • Give boundary test values for an input that must be between 1 and 10.
  • Why are logic errors the hardest to find?

Practice questions

  1. 1. A program runs without crashing but calculates the wrong average. This is a...

    • A. syntax error
    • B. runtime error
    • C. logic error
    • D. compiler error
    Show answer

    Answer: logic error

    Logic errors let the program run but give wrong results, such as forgetting brackets so only one value is divided.

  2. 2. For an input that must be between 0 and 100, which set contains boundary test data?

    • A. 45, 60, 75
    • B. 0, 100
    • C. −5, 150
    • D. 'ten', 'abc'
    Show answer

    Answer: 0, 100

    Boundary data lie exactly at the edges of the valid range (0 and 100); the others are normal or invalid data.

On WeLearn

The full lesson: reading notes, worked examples, class activities and the Unit 6 quiz

Study Testing and Debugging Programs on WeLearn

Teach Testing and Debugging Programs with WeLearn

We will bring a demo to your school: a lesson on your interactive TV, a virtual lab and a classroom game, with your own teachers.