Next: , Previous: Project Attributes for gnattest, Up: Creating Unit Tests Using gnattest

26.4 Simple Example

Let's take a very simple example using the first gnattest example located in:


This project contains a simple package containing one subprogram. By running gnattest:

     $ gnattest --harness-dir=driver -Psimple.gpr

a test driver is created in directory "driver". It can be compiled and run:

     $ cd driver
     $ gprbuild -Ptest_driver
     $ test_runner

One failed test with diagnosis "test not implemented" is reported. Since no special output option was specified, the test package Simple.Tests is located in:


For each package containing visible subprograms, a child test package is generated. It contains one test routine per tested subprogram. Each declaration of a test subprogram has a comment specifying which tested subprogram it corresponds to. All of the test routines have separate bodies. The test routine located at simple-tests-test_inc_5eaee3.adb contains a single statement: a call to procedure Assert. It has two arguments: the Boolean expression we want to check and the diagnosis message to display if the condition is false.

That is where actual testing code should be written after a proper setup. An actual check can be performed by replacing the Assert call with:

     Assert (Inc (1) = 2, "wrong incrementation");

After recompiling and running the test driver, one successfully passed test is reported.