Skip to content

Refactor: Modularise unit tests

Dear @micael.oliveira @martin.lueders @nicolastd @sohlmann @hmenke @LecrisUT

I'd like to gather your thoughts on breaking up the current component tests (with the latter aim of moving to unit/component tests compiled as separate binary/binaries). My initial suggestion is as follows:

We currently have a single, monstrously large (2201 lines) file for running unit and component tests: src/main/test.F90.

I propose splitting this up such that we have:

root
  src/
  unit_tests/
    basic/
      test_sort.F90
      ...
    boxes/
    classical/
    ...
  testsuite/
  ...

which is consistent with test directory structure in modern projects. src/main/test.F90 is retained as a top-level driver, which contains:

 subroutine test_run(namespace)
    type(namespace_t),       intent(in)    :: namespace

    type(test_parameters_t) :: param
    integer :: test_mode

    PUSH_SUB(test_run)

    call messages_obsolete_variable(namespace, 'WhichTest', 'TestMode')

    !%Variable TestMode
    !%Type integer
    !%Default hartree
    !%Section Calculation Modes

    call messages_print_with_emphasis(msg="Test mode", namespace=namespace)
    call messages_print_var_option("TestMode", test_mode, namespace=namespace)
    call messages_print_var_option("TestType", param%type, namespace=namespace)
    call messages_print_var_value("TestRepetitions", param%repetitions, namespace=namespace)
    call messages_print_var_value("TestMinBlockSize", param%min_blocksize, namespace=namespace)
    call messages_print_var_value("TestMaxBlockSize", param%max_blocksize, namespace=namespace)
    call messages_print_with_emphasis(namespace=namespace)

    select case (test_mode)
    case (OPTION__TESTMODE__HARTREE)
      call test_hartree(param, namespace)
    case (OPTION__TESTMODE__DERIVATIVES)
      call test_derivatives(param, namespace)
    case (OPTION__TESTMODE__ORTHOGONALIZATION)
      call test_orthogonalization(param, namespace)
    case (OPTION__TESTMODE__INTERPOLATION)
      call test_interpolation(param, namespace)

  ...

and uses modules that contain the test routines. I note that Cristian already created a test/ folder. We might want to use this instead of creating unit_tests/, or consider renaming it.

Ultimately this is a small structural change, but it makes the test files more modular and visible, which I think is a good thing.

Edited by Alex Buccheri