Instructor companion slides
University College London
2026-11-11
“If the parts don’t work by themselves, they probably won’t work well together”
(Thomas and Hunt, 2019, The pragmatic programmer, Topic 51).
Unit tests are:
Benefits of unit tests:
Objectives
Throughout this workshop we will look at two libraries:
You will be writing tests for the temperature conversion library provided in the exercises.
I will provide worked examples from this matrix operations library
First, how can we test this library using standard Fortran?
solution/standard_fortran/test_temp_conversions.f90
What makes this implementation good? What makes it bad?
Good:
Bad:
Objectives
Supports testing MPI parallelised code, including parameterising tests by number of MPI ranks.
A few other reasons:
Starting with the standard Fortran test we saw earlier, follow along writing tests for the temperature conversion library.
Now that we have written a test using pFUnit, let’s build it using CMake. Follow along to build your newly written pFUnit test of the temperature conversion library
.pf files into .F90.@assertEqual.add_pfunit_ctest.Objectives
And…
It will be much easier when testing MPI parallelised Fortran.
What problems are there with the test we’ve just written? What happens in the case when one test scenario fails?
Starting with the pFUnit tests we have just written, follow along parameterising your tests for the temperature conversion library.
TestCase.AbstractTestParameter.Objectives
Some tips for writing testable MPI code:
Despite what I said earlier, we will look at two more libraries:
I will continue with an MPI parallelised version of the matrix operations library.
You will be writing tests for the mpi_utils library provided in the exercises.
Let’s look at the MPI parallel matrix operations code we’ll be testing. Follow along writing MPI parallel tests for the MPI utilities library.
Thus far, we have assumed all ranks should expected the same result during our tests. However, this is often not the case.
Let’s continue writing tests for the matrix operations library and remember to follow along.
The full workshop notes can be found in the software carpentries incubator if you wish to read through them in your own time. More exercises can also be found in the exercises directory of the workshop notes repository.
Scan to view the slides

Unit testing in Fortran workshop - Back to talks