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. Compile Fizzbuzz.cbl with the MFUPP preprocessor:
    cobol Fizzbuzz.cbl int"" preprocess"mfupp" verbose endp;
  2. Ensure that MFUPD_Fizzbuzz.cpy is in the same working directory as Fizzbuzz.int.
  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. Compile Fizzbuzz.cbl with the MFUPP preprocessor:
    cobol Fizzbuzz.cbl int"" preprocess"mfupp" verbose endp;
  2. Ensure that MFUPD_Fizzbuzz.cpy, MFUWS_Fizzbuzz.cpy, and fizzbuzz_data.csv are all in the same working directory as Fizzbuzz.int.
  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.