Elements of a Test Fixture

The elements of a complete test fixture are coded as entry points in a COBOL program. The entry points shown here are using call prototypes found in the mfunit.cpy copybook, available from the cpylib folder of your product installation directory. If you are unable to use the copybook due to its level-78 items, which are not supported with mainframe dialects, you must specify the following entry point names:

Element Entry point
test setup MFUS_test_case_name
test metadata setup MFUM_test_case_name
test case MFUT_test_case_name
test teardown MFUE_test_case_name
global metadata MFUGM_program_name
global command line arguments MFUGA_CMDOptions

The main elements are:

The test setup
Any pre-requisite conditions that need to be satisfied before the test case is run can be set up in this section. For example, if the test case requires that a data file already exists or is open ready for input, you can code such things in this section. This section is optional.
...
entry MFU-TC-SETUP-PREFIX & "MyTestCase"
//initial setup code goes here//
goback
...
The test metadata setup
There are a number of metadata details that you add directly through your source code that can relate to a single test case, such as test description and test timeout; see Using Dynamic Metadata. This section is optional.
...
entry MFU-TC-METADATA-SETUP-PREFIX & "MyTestCase"
//initial metadata setup code goes here//
goback
...
The test case
This section contains the actual testing logic and test assertions.
...
entry MFU-TC-PREFIX & "MyTestCase"
//test case code goes here//
goback
...
The test teardown
This section enables you to tidy up the environment, such as releasing or closing resources, after the test has been run. This may be critical if you run multiple test cases within a test suite. This section is optional.
...
entry MFU-TC-TEARDOWN-PREFIX & "MyTestCase"
//clean-up code goes here//
goback
...

If you have multiple test cases, each must have their own setup and teardown. COBOL programs that contain more than one test fixture are commonly referred to as test suites.

These sections can appear in your code in any order, but are run in the order shown here.

There are also other elements that affect a test case, either by applying a number of attributes (metadata) to the test cases, or setting command line options for the test run:

The global command line options
You can add test runner command line arguments within the MFU-GLOBAL-COMMANDLINE-PREFIX entry point. The arguments should be set in the COBOL variable MFU-GLOBAL-COMMANDLINE-ARG, which is available through the mfunit.cpy copybook. This section is optional.
...
entry MFU-GLOBAL-COMMANDLINE-PREFIX & "MyProgramName"
//global command line arguments here//
//for example: move "-verbose -high-res-timer:true -report:markdown to MFU-GLOBAL-COMMANDLINE-ARG
goback
...
See Examples of Using Metadata for a more comprehensive example of using this entry point.
The global metadata setup
There are a number of metadata details that you add directly through your source code that can relate to all test cases within the test fixture. For example, you can add a trait to all test case in the test fixture file. This section is optional.
...
entry MFU-GLOBAL-METADATA-PREFIX & "CMDOptions"
//global metadata is set up here//
goback
...
Note: You can specify any literal name within parentheses in place of "CMDOptions".
See Examples of Using Metadata for a more comprehensive example of using this entry point.