Testing

Testing is the process of executing programs with the intention of finding errors. We describe in our Common Error Checklist the types of error for which to test and provide some examples of syntax errors, run-time errors and logic errors. Testing establishes the existence of defects. Debugging, to be the subject of our next tutorial, locates and corrects these defects.

Exam courses may cover, in the theory at least, many types of testing such as dry runs, unit testing, module testing, black box testing, white box testing, regression testing, integration testing, system testing, stress testing, alpha testing, beta testing and acceptance testing. Here we give a practical guide to testing small programs and show how black box and white box testing can be used in combination to good effect.

In Testing Example, we provide a program to test then tabulate and execute our plan for black box testing. Program crashes can be vary annoying and should be prevented. Even worse is a program that appears to be working but gives believable output that is wrong. We compare our test results with expected percentages that we have worked out manually or with the aid of a spreadsheet.

Automated testing is not a common feature of A-level coursework, but we suggest it as a way of making testing more satisfying and thorough. In the second section, we show how procedure Test automates the testing. We use conditional compilation to produce one executable for testing and another, without the test procedure, for normal use. White box testing (sometimes called structural testing) should test different paths through the code. We demonstrate the use of a code coverage tool and then analyse manually the coverage of possible combinations of multiple conditions. We examine loops to see if they have been tested adequately by our black box tests.

We demonstrate another way of performing automated testing in the third section. We put the procedure to be tested in one unit and the tests in a different unit. The main program that executes the tests is built into Lazarus. The main program for normal use is a tiny file that merely calls the procedure in another unit.

We conclude by summarising best practice with Testing Tips.

Follow these links to the sections described above.

Programming - a skill for life!

Pascal Programming Tutorials