Chapter 1

Testing and Debugging

Testing runs a program with different kinds of data to reveal errors; debugging finds and fixes those errors.

Testing and debugging are different jobs. Testing reveals that something is wrong; debugging fixes what is wrong.

Three kinds of test data

A good test tries several kinds of input so hidden faults appear:

  • Normal data — typical, valid values the program expects, e.g. a mark of 55.
  • Boundary data — values at the edge of the valid range, e.g. 0 and 100 for a mark.
  • Abnormal data — invalid values the program should reject, e.g. a letter or 150 for a mark.

Key idea

Testing shows an error exists; debugging removes it. Always test with normal, boundary and abnormal data, not just one "easy" value.

Three types of error

Debugging classifies errors so they are easier to fix:

  • Syntax error — breaks the language rules, e.g. a missing bracket; the program will not run.
  • Logic error — the program runs but gives the wrong answer, e.g. using + instead of ×.
  • Runtime error — the program stops while running, e.g. dividing by zero.

Example

A program should output area = length × width but a programmer types area = length + width. There is no syntax error, so it runs, but the area is wrong. This is a logic error, found by testing with length 5 and width 4 (expected 20, but it shows 9).

Remember

  • A syntax error stops the program from running at all.
  • A logic error runs but produces wrong output.
  • Debugging is the act of fixing the error you found.

Stuck on this topic? A verified JomKelas tutor can walk you through it.

Find a verified tutor