Inserting Test Code into Source Code

When your source code is compiled with the MFUPP preprocessor, it can be run within the Micro Focus Unit Testing Framework alongside copybooks that contain the unit test code and any accompanying data.

If the source program and the copybooks are stored in the same location, and adhere to the naming conventions stated below, they can be run as one unit of work. These self contained tests require the source code to have a program-id, as this name is used to identify the copybooks to run during a test run.

The following overview shows the areas of insertion into the source code:

        Identification Division
        Program-Id. MYSRC.
        Environment Division
        Data Division
        Working-Storage Section
          \____________________________ MFUWS_MYSRC

        Local-Storage Section
        Linkage Section.
          \____________________________ MFULK_MYSRC

        Procedure Division
          GOTO MFUPP--START-OF-PROGRAM                *> INSERTED BY MFUPP
          \____________________________ MFUPD_MYSRC
          
         MFUPP--START-OF-PROGRAM SECTION.             *> INSERTED BY MFUPP
          \____________________________ MFUPDS_MYSRC
File name Description
MFUWS_prog-id.cpy The additional test data items that are not already defined in the source program. These items are inserted into working-storage when the test case is run.

prog-id is the program-id of the source program under test.

MFULK_prog-id.cpy The additional linkage data items that are not already defined in the source program. These items are inserted into the Linkage Section when the test case is run.

prog-id is the program-id of the source program under test.

MFUPD_prog-id.cpy The test case code (including the setup, teardown, etc...) to be run against the source code. This is inserted as an entry point at the start of the procedure division of the source under test. Code the entry point as you would any other unit test.

prog-id is the program-id of the source program under test.

MFUPDS_prog-id.cpy Initial section or paragraph to add to the source program, to set up any linkage items, for example, if your CICS program uses a COMMAREA, or if the path of the test run file is required to call into other programs. This copybook is inserted before the first line of code under test is executed.

Test cases that follow such a path must ensure that the program under test is reentrant. If you receive a COBRT166 Recusive COBOL CALL is illegal (Fatal) message when running the test, you may need to recompile the program with the RENTRANT directive or change the dialect.

Note: You can change the MFUWS_ MFULK_, MFUPD, and MFUPDS prefixes in the above naming conventions by using the WS-PREFIX, LK-PREFIX, PD-PREFIX, and PDS-PREFIX directives; see MFUPP Directives.

Once the source code is compiled with the additional copybooks, the test runner can execute the test case(s) against the source code as one unit of work.

To run through a couple of test run examples that use these copybooks, see Examples of Using the MFUPP Preprocessor.