Create a Self-Contained COBOL Unit Test

Use this process to create a self-contained test, which is a copybook that is inserted into the source program of a native COBOL or mainframe project when run under the Micro Focus Unit Testing Framework.

You should have already created a unit test project in which to store this unit test. Due to the strict naming conventions for the copybook containing this type of test, create each self-contained test in its own unit test project. However, you can create multiple projects that test the same source program.

  1. While in the COBOL perspective, select the unit test project in the COBOL Explorer pane.
  2. Right-click the project, point to New, and select COBOL Unit Test.

    The New COBOL Unit Test dialog box appears.

  3. Select Self Contained Unit Test, and then click Next.
  4. In the Containing project field, ensure it states the name of your unit test project.
  5. Click Browse to the right of the Program under test field, select the program that contains the code you want to test, then click OK.
  6. Click Finish.
    In the unit test project:
    • A copybook is created that when run through the Micro Focus Unit Testing Framework will be inserted into the source code for the duration of the test run; this is where you add your test code. The name of the copybook is important: it must consist of the program-id of the source program, prefixed MFUPD_, in order that both the source and the test run as a single unit of work during the test run. To create further test cases, add further entry points (prefixed MFUT_) to the copybook.

      MFUPD copybook

      Tip: Create an additional copybook, MFUWS_<prog-name>.cpy, to include additional working storage items that your test case requires for the test run. <prog-name> must be the same name as used for the MFUPD_ copybook.
    • A link to the program under test is added.

      Linked resource file

    • Within the properties of the linked file resource, the MFUPP preprocessor has been enabled.

      The MFUPP preprocessor

    • A number of other project properties and copypaths are also copied over from the project under test in order for all files to run as a single unit of work during the test run.