Menu

Testing

Iterative Testing

Iterative testing is testing that happens during development, while a program is still being written. Rather than waiting until everything is finished, you test each module — one self-contained part of the program, such as a single function — as soon as you have written it.

It is also called incremental testing, because the program is built up one module at a time and each new piece is checked as it is added.

The repeated cycle

  1. Write a module.
  2. Test it with some chosen data.
  3. Fix any errors the test shows up.
  4. Retest to check the fix worked.

That cycle then repeats for the next module, and the next, until the program is complete.

Working this way means errors are found early, while the module is small and still fresh in your mind. A mistake inside ten lines is quick to spot and put right; the same mistake buried in a finished program of many hundreds of lines can take a long time to track down.

Testing a module, not the whole program

Iterative testing checks modules individually instead of testing the whole finished program — that is the key difference from final testing at the end of production.

For example, imagine a music app that stores the length of every song on a playlist in a list. One module, count_long_songs(), should return how many of those songs are longer than three minutes. The list holds 2.5, 4.0, 3.5, 2.0 and 5.0 minutes, so the answer should be 3. You write it, test it with that list, and it returns 2, because the loop stopped one item before the end of the list, so the last song was never checked. You change the loop so it runs all the way to the end of the list, retest with the same list, see 3, and only then start the module that adds up the total playing time. The error was caught in seconds, in code you had just written.

Practise this