Using MFUPP to Mock and Stub a Program

Use the following example to mock the source code, and then control the flow of execution through the Micro Focus Unit Testing Framework. The test uses both mocking and stubbing techniques to skip and substitute code from the source program under test.

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

  • getCustomerAccountInfo.cbl
  • getCustomerId.cbl
  • MFUT_TESTCUSTOMER.cbl
  1. Compile getCustomerAccountInfo.cbl with the MFUPP preprocessor:
    cobol getCustomerAccountInfo.cbl preprocess"mfupp" mock confirm verbose endp int() verbose sql();
    Note: The sql() directive is required as there is some SQL syntax in the source code.
  2. Compile getCustomerId.cbl with the MFUPP preprocessor:
    cobol getCustomerId.cbl preprocess"mfupp" mock confirm  verbose endp int() verbose sql();

    This file is compiled with the same directives as the first file.

  3. Compile MFUT_TESTCUSTOMER.cbl for use with the Micro Focus Unit Testing Framework:
    cbllink -D MFUT_TESTCUSTOMER.cbl

    The test case is compiled and linked into the Micro Focus Unit Testing Framework.

  4. Run MFUT_TESTCUSTOMER.int through the Micro Focus Unit Testing Framework:
    mfurun -verbose -junit-packname:com.microfocus.mfupp.native -report:junit MFUT_TESTCUSTOMER

    As long as the test case is run in the same folder as the two previously compiled files, it will put those two files under test, returning to its controller entry point each time a call is made to either of the other programs. On a couple of occasions, the controller redirects flow to the MOCK-REDIRECTOR entry point to retrieve some customer details for the purposes of the test.