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:
cobol getCustomerAccountInfo.cbl preprocess"mfupp" mock confirm verbose endp int() verbose sql();
cobol getCustomerId.cbl preprocess"mfupp" mock confirm verbose endp int() verbose sql();
This file is compiled with the same directives as the first file.
cbllink -D MFUT_TESTCUSTOMER.cbl
The test case is compiled and linked into 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.