Testing

Testing is essential if you want to have any faith that your programs work.

The easiest way to test a program is if you've written your examples in the Definitions pane using check-expect. If so, you can just click "Run" and you'll see a report showing how many of your tests the program passed, how many and which ones it failed. Clicking on any of the failed tests will take you to the location of that test in the Definitions pane.

When your program fails a test, one of two things has happened: either your "right answer" was wrong (possible, though unlikely), or there's a bug in the program. Once you've ruled out the first possibility, think about what could have caused the bug. Since you should have multiple test cases, look at all of them in search of patterns. If some of them are right and others are wrong, the pattern of which ones are right and which wrong will help you track down the problem. If all of them are wrong in the same way, this pattern will help you track down the problem. And so on. Above all, do not make random changes to the program and "hope" the problem goes away; this is much more likely to create additional bugs than to kill the one you've already got.

Once you think you've fixed the bug, run the tests again and see if it passes now. And be sure to re-examine the previously working examples to make sure they still work (i.e. you haven't fixed one bug by creating another!)


Last modified: Mon Aug 25 12:29:03 EDT 2008
Stephen Bloch / sbloch@adelphi.edu