Skip to content

Setup unit testing with CMake and pFUnit #17

@tlestang

Description

@tlestang

A minimum setup could be

  • Basic CMakeLists.txt for configuration and particularly interfacing with pFUnit.
  • A couple of placeholder unit tests to "test the testing".
  • Build and cache pFUnit in the GH actions workflow, build the test executable and run the tests.

Currently (17.02.2022) some tests are implemented in the hack_doconcurrent branch using CTest and pFUnit, so I'm assuming some of you know about this testing framework. pFUnit looks like a popular option for fortran. It's maybe not as well documented and feature-rich as frameworks in other languages, but seems to be used by many projects out there. Alternatives are Funit, FRUIT and Ftunit but pFUnit is the only one that ibviusly looks actively maintained?

I've played around with it, it's straightforward to install and use. At least following basic examples available at

https://github.com/Goddard-Fortran-Ecosystem/pFUnit_demos

It also had support for MPI. I don't know if this is common among fortran frameworks, but it sounds relevant to me.

Tests are written in free form fortran, e.g.

@test
subroutine test_square()
   use Square_mod
   use funit

   @assertEqual(9., square(3.), 'square(3)')
   
end subroutine test_square

that is meant to be parsed and compiled. But a CMake module is provided that takes care of everything, so that

add_pfunit_ctest (my_tests
  TEST_SOURCES ${test_srcs}
  LINK_LIBRARIES sut # your application library
  )

should be enough to generate test executable my_tests. See Using pFUnit.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions