Fortran unit tests using the FRUIT framework are similar in structure to the Google Test tests for C and C++ described above.
The contents of a typical FRUIT test file look like this:
module <test_case_name> use iso_c_binding use fruit use <your_code_module_name> implicit none contains subroutine test_name_1 ! Test 1 code here... ! call assert_equals(...) end subroutine test_name_1 subroutine test_name_2 ! Test 2 code here... ! call assert_true(...) end subroutine test_name_2 ! Etc.
The tests in a FRUIT test file are placed in a Fortran module named for the test case name, such as the name of the C++ class whose Fortran interface is being tested. Each unit test is in its own Fortran subroutine named for the test name, which indicates the functionality being verified by the unit test. Within each unit test, logical assertions are defined using FRUIT methods. Failure of expected values will cause the test to fail, but other tests will continue to run.
Note that each FRUIT test file defines an executable Fortran program. The program is defined at the end of the test file and is organized as follows:
program fortran_test use fruit use <your_component_unit_name> implicit none logical ok ! initialize fruit call init_fruit ! run tests call test_name_1 call test_name_2 ! compile summary and finalize fruit call fruit_summary call fruit_finalize call is_all_successful(ok) if (.not. ok) then call exit(1) endif end program fortran_test
Please refer to the FRUIT documentation for more information.