Skip to content

Unit Testing

Chris MacMackin edited this page Feb 15, 2016 · 2 revisions

FIAT is to be written using test-driven development (TDD). This means that code should be written in the following order:

  1. Write the signature of the public procedures in a module. Public, here, may include private procedures which are bound to publicly available types.
  2. Write a unit test in such a way as to check all behaviour expected from this procedure, without relying on the behaviour of any of your other procedures.
  3. Implement the procedure.

Due to encapsulation, it can be impossible to test only one type-bound procedure of a derived type without relying on any others. In such situations, it is acceptable to make use of getter and setter methods, including in the setup and teardown phases of testing. It may not be necessary to write a dedicated test for the getter and setter routines in such a situation, so long as they are being implicitly tested by their use in other tests. The goal should always be to have 100% test coverage, although if there is a stop statement within the code then it will not be possible to have tests reach this line without crashing the test program.

##Test Framework The pFUnit test framework is used to test FORD. This consists of a runtime library for performing assertions, as well as a preprocessor which must be used on your test files. See the installation instructions for information on obtaining pFUnit and installing it on your system.

Tests (stored in the folder of the same name) are located in files with the extension pf. The pFUnit documentation provides information on how to make use of the preprocessor to write your tests. For FIAT, each module should have a corresponding test module with the same name but the suffix _test_mod appended. The file containing this test module should have the same name as the module except without the _mod suffix. As described in the pFUnit usage instructions, an entry for each test module must be added to the file testSuites.inc. The entry takes the form

ADD_TEST_SUITE(test-module-name_suite)

The unit tests can be compiled and run with the command make tests.

Clone this wiki locally