MyLeoNes™

Testing programs — Computing, 7–10

A program can run without crashing and still give the wrong answer. Testing means trying planned examples, including unusual ones, to see whether the program behaves as intended before people rely on it.

Ask the program questions

Testing is like checking a torch with fresh batteries before taking it outside. You give a program an input, predict the result, run it and compare what happened with what should happen. One successful try is useful, but it cannot prove that every situation is correct.

Why test at all?

People write programs for rules that have many possible inputs, and people can misunderstand a rule or forget an edge case. A test finds these problems while the program is still being made, when changing it is easier. Testing is not only for broken-looking programs: a quiet wrong answer can be more dangerous than a crash.

Testing a points rule

A game says: a player gets 3 points for each star. First, predict a test with 0 stars: the score should be 0. Next, try 2 stars: 2 × 3 gives 6. Then try 10 stars: the answer should be 30. If the program says 9 for 2 stars, the rule or its code needs checking.

It ran, so it must be right

A program that opens and responds may look finished, so it is natural to trust it. But running only shows that this one path happened; it does not check every input or choice. Test normal values, zero, the smallest and largest allowed values, and something unexpected when the rules say it should be handled.

Testing in real life

Before a weather app, ticket machine or school timetable is trusted, its makers test many situations. They might check a very hot day, a sold-out train or a holiday date. Testing also appears when you try a new recipe or check a bridge model: you compare what you expected with what actually happened.

Keep exploring

Other languages

Loading MyLeoNes™…