Using MFUPP to Insert Test Code Into a Program

Example 1

Use the following example to inject unit test code into your source code, and then run it through the Micro Focus Unit Testing Framework. The test uses hard-coded data specified within the test code.

It consists of two files, which can be found in the appendix:

  • Fizzbuzz.cbl - a COBOL program containing a section that will be put under test.
  • MFUPD_Fizzbuzz.cpy - a copybook that contains an entry point to be inserted into the COBOL program.
  1. Create Fizzbuzz.cbl and MFUPD_Fizzbuzz.cpy, and populate these files with the code in the appendix.
    Note: Ensure these files are created in the same folder.
  2. Compile Fizzbuzz.cbl with the MFUPP preprocessor:
    cobol Fizzbuzz.cbl int"" preprocess"mfupp" verbose endp;
  3. Run Fizzbuzz.int through the Micro Focus Unit Testing Framework:
    mfurun Fizzbuzz.int

    As the program runs, it executes the code in the entry point within MFUPD_Fizzbuzz.cpy, which in turn executes the Process-Number section of the original source code, testing it against its own data.

Example 2

Use the following example to inject data-driven unit test code into your source code. This example requires an additional copybook to inject the fields from the data file into the working-storage section, and then uses the values in the referenced .csv file to iterate through the test code..

It consists of four files, which can be found in the appendix:

  • Fizzbuzz.cbl - a COBOL program containing a section that will be put under test.
  • MFUWS_Fizzbuzz.cpy - a copybook that contains the working-storage definitions for the data file fields.
  • MFUPD_Fizzbuzz.cpy - a copybook that contains an entry point to be inserted into the COBOL program.
  • fizzbuzz_data.csv - the data file that contains the values that will run through the code under test.
  1. Create MFUPD_Fizzbuzz.cpy, MFUWS_Fizzbuzz.cpy, and fizzbuzz_data.csv, and populate these files with the code in the appendix.
    Note: Ensure these files are created in the same folder.
  2. Compile Fizzbuzz.cbl with the MFUPP preprocessor:
    cobol Fizzbuzz.cbl int"" preprocess"mfupp" verbose endp;
  3. Run Fizzbuzz.int through the Micro Focus Unit Testing Framework:
    mfurun -verbose:true Fizzbuzz.int

    As the program runs, it executes the code in the entry point within MFUPD_Fizzbuzz.cpy a number of times (once for each value in fizzbuzz_data.csv), each time executing the Process-Number section of the original source code.