JCL Test Case Example

Your Micro Focus product contains an example unit test and JCL job card that you can use together with a JES-enabled enterprise server region. Run using the test runner syntax on the command line, you can run the unit test which will submit the job card to the enterprise server region, and then query the resulting return code of the JCL job and perform a number of test assertions.

The example source files are located in the C:\Documents and Settings\All Users\Documents\Micro Focus\Visual COBOL\Samples\Mainframe\UnitTests\JCL_COBOL\Example1 directory.

  • txtdiff.jcl - the JCL job card. This job runs the IEBCOMPR utility to compare two blocks of data.
  • MFUT_TXTDIFF1.cbl - the test program that contains the unit test. The unit test uses JCL-specific metadata to identify the job card (MFU-MD-JCL-FILE-NAME), and then capture a number of job details (MFU-MD-JCL-COND-TYPE, MFU-MD-JCL-COND-CODE, and MFU-MD-JCL-JOB-NBR) after the test has run, then makes its test assertion by setting the MFU-MD-JCL-TESTCASE-PASSED variable accordingly (true or false).

To run the test, you also need a running JES-enabled enterprise server region - the following example uses a region called ESMFUJCL, and a catalog located in the c:\ESMFUJCL\ directory.

To run the example:

  1. Compile the test program:
    cbllink -D MFUT_TXTDIFF1.cbl

    This produces the required executable test file.

  2. Run the test, supplying details of the JES-enabled region and a JES catalog:
    The JCL job referenced in the unit test is submitted to the spool queue. The job requires a class A batch initiator, and so the test will wait, displaying the following output, if one is not already running within the region.
    Fixture : MFUT_TXTDIFF1
     Executing test case : MFUT_TXTDIFF1
  3. Start a batch initiator for class A, if required.

    The test runs and a summary similar to the following should display:

    Micro Focus COBOL - mfurun Utility
    Unit Testing Framework for Windows/Native/32
    
    Fixture : MFUT_TXTDIFF1
     Executing test case : MFUT_TXTDIFF1
      JCLCM0188I J0001037 IEBCOM01 JOB  STARTED 14:38:29
      JCLCM0182I J0001037 IEBCOM01 JOB  ENDED   - COND CODE 0008 14:38:29
     Completed test case : MFUT_TXTDIFF1 - Passed
     Generating report : MFUT_TXTDIFF1-report.txt
    
    Test Run Summary
     Overall Result           Passed
     Tests run                1
     Tests passed             1
     Tests failed             0
     Total execution time     4255

    During the test run, the generated report (MFUT_TXTDIFF1-report.txt) was read by the COBOL program in order to make the test assertions shown in the summary.