This project offers a lightweight, procedural unit testing framework based on nothing but standard Fortran. Integration with meson, cmake and Fortran package manager (fpm) is available. Alternatively, the testdrive.F90 source file can be redistributed in the project's testsuite as well.
The test-drive tests will run with the rest of the cmake or fpm tests in the repo.
There is a known issue that the tests for test-drive itself will also be ran by ctest as shown below
$ ctest
Test project /Users/connoraird/work/fortran-tooling/build
Start 1: fortran-tooling-test-drive/mesh_generator
1/4 Test #1: fortran-tooling-test-drive/mesh_generator ... Passed 0.33 sec
Start 2: test-drive/all-tests
2/4 Test #2: test-drive/all-tests ........................ Passed 0.33 sec
Start 3: test-drive/check
3/4 Test #3: test-drive/check ............................ Passed 0.01 sec
Start 4: test-drive/select
4/4 Test #4: test-drive/select ........................... Passed 0.01 sec
100% tests passed, 0 tests failed out of 4
Total Test time (real) = 0.69 sec
Compilers tested: GNU Fortran (Homebrew GCC 14.2.0_1)
| Feature | Implemented natively | Implemented manually |
|---|---|---|
| Can run individual tests | No | Yes, see main.f90. However, this requires running the test executable directly without ctest. |
| Mocking/Stubbing | No | Not implemented |
| Data driven tests | No | Yes, but this is very cumbersome. See verify_calculate_mesh_parameters and verify_calculate_mesh in test_mesh_generator.f90 |
| Coverage report | Yes, with fpm | N/A |
| Skip tests | Yes, see test_skip_example in test_mesh_generator.f90 |
N/A |
fpm provided a very convenient way to get started with test-drive. However, it is unlikely that a long running Fortran project written in Fortran 95, for example, will be using fpm. It is more likely that cmake is in use. cmake can be used to install