Unit tests in PARALLAX are managed using pFUnit. To enable unit testing, PARALLAX must be compiled with the -DPARALLAX_ENABLE_UTESTS=ON flag. This will generate executables named PARALLAX-utests-<name>, which can be run individually or collectively using CTest. Since PARALLAX includes some MPI-parallelized features, tests may need to be executed with up to 4 MPI processes.
Any new feature developed in PARALLAX should be accompanied by unit tests. While PARALLAX may not strictly follow the textbook definition of a unit test, we consider unit tests at the module level, meaning each module and its functionalities should ideally have corresponding unit tests. When designing unit tests, please consider the following guidelines:
Here you may find a template for a unit test file.
module test_foo_m
!! Contains tests for foo module
use MPI
use pfunit
use screen_io_m, only : get_stdout
implicit none
contains
@test(npes = [4])
! This test uses MPI
subroutine test_foo(this)
!! Unit test for foo, testing specific aspect
use MPI
use foo_m, only : foo_t
implicit none
class (MpiTestMethod), intent(inout) :: this
integer :: comm_world, rank, nprocs, ierr
comm_world = this%getMpiCommunicator()
call MPI_COMM_rank(comm_world, rank, ierr)
call MPI_COMM_size(comm_world, nprocs, ierr)
! Write message to screen, to show that this test was actually run
if (rank == 0) then
write(get_stdout(),'(A80)') &
'test_foo ' //repeat('-',80)
endif
! Perform tests via assert functions
...
@assertEqual(returned_value, expected_value)
...
! Write message to screen, to show that this test was actually completed
if (rank == 0) then
write(get_stdout(),'(A80)') &
'test_foo '//repeat('-',80)
endif
end subroutine
...
! Maybe add further test, testing further aspects of foo
end module