Dear all,
I tried to find any existing documentation about Fortran and Unit testing in Visual Studio but couldn't find any. Do you have experience with Unit Testing for Fortran, can you recommend some good tutorials or books for that topic? The tools need to integrate into the Visual Studio 19 environment and I would love to use the built in Test-Explorer. (I use the Intel Compiler, but that should not matter for testing, right?)
best regards,
There are several Fortran unit testing tools out there: http://fortranwiki.org/fortran/show/Unit+testing+frameworks I guess you should check them first.
dongli created this easy applicable library for Fortran unit testing:
https://github.com/dongli/fortran-unit-test
The following sample shows the usage of this library:
program good_test
use unit_test
implicit none
type(test_suite_type) specific_suite
! example with default suite
call test_case_init()
call test_case_create('Test 1')
! By sending macros __FILE__ and __LINE__, report will print the file and line number where assertion fails.
call assert_approximate(1.0, 2.0, __FILE__, __LINE__) ! line 14
call test_suite_report()
call test_case_final()
! example with specific suite
specific_suite%name = 'my specific test suite'
call test_case_create('Specific Test 1', specific_suite)
! suite = SUITE need in this case (cause optional argument eps, file_name, line_number is missing)
call assert_approximate(1.0, 2.0, suite=specific_suite)
call test_case_create('Specific Test 2', specific_suite)
! suite = SUITE need in this case (cause optional argument eps is missing)
call assert_equal(1.0, 2.0, __FILE__, __LINE__, suite=specific_suite)
call test_case_create('Specific Test 3', specific_suite)
call assert_approximate(1.0, 2.0, __FILE__, __LINE__, 1E-0, specific_suite)
! report a test_case
call test_case_report('Specific Test 2', specific_suite)
! report the complete suite
call test_suite_report(specific_suite)
call test_case_final(specific_suite)
end program good_test
The output looks like:
///////////////////// Report of Suite: Default test suite ///////////////////////
+-> Details:
| |
| +-> Test 1: 1 of 1 assertions succeed.
| |
|
+-> Summary:
| +-> Default test suite: 1 of 1 assertions succeed.
////////////////////////////////////////////////////////////////////////////////
//////// Report of Suite: my specific test suite, Case: Specific Test 2 /////////
+-> Specific Test 2: 0 of 1 assertions succeed.
| |
| +-> Assertion #1 failed with reason: x ( 1.000) == y ( 2.000)
| +-> Check line: test_assert.F90:29
/////////////////// Report of Suite: my specific test suite /////////////////////
+-> Details:
| |
| +-> Specific Test 1: 1 of 1 assertions succeed.
| |
| +-> Specific Test 2: 0 of 1 assertions succeed.
| | |
| | +-> Assertion #1 failed with reason: x ( 1.000) == y ( 2.000)
| | +-> Check line: test_assert.F90:29
| |
| +-> Specific Test 3: 0 of 1 assertions succeed.
| | |
| | +-> Assertion #1 failed with reason: x ( 1.000) =~ y ( 2.000)
| | +-> Check line: test_assert.F90:32
| |
|
+-> Summary:
| +-> my specific test suite: 1 of 3 assertions succeed.
////////////////////////////////////////////////////////////////////////////////
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With