Modify data to test different paths in the ZUnit test case of TOURFILE.cbl

In the test case editor, you can modify the data to test different code paths. This procedure also includes the procedure of finding errors in the application and fixing them using the ZUnit test case.

Before you begin

This procedure uses a sample program included with IBM® Developer for z/OS®. It also uses a z/OS project that was created by the sample record and import procedure. Before using this procedure, follow the instructions in Record and import data into the ZUnit test case of TOURFILE.cbl.

About this task

This TOURFILE.cbl has an IF statement for discounting the total expense when the value of NUMBER-ENTRIES is 10 or above. Here we modify this value to test different code paths.

Procedure

  1. Add TEST2 - discount case.
    1. Right-click TEST1 in the Tests pane, and click Duplicate Test. You can also do this by using the test case editor toolbar buttons.
      A TEST2 is duplicated from TEST1. You can double-click TEST2 and change its description to Discount in the Edit Test window to make it clearer.
      Test case editor 1
    2. In the test case editor, find the TOURDATA - Input file/Record:Record1/DATA-REC/I-NUMBER-ENTRIES item, and change its value from 2 to 10. Find TOURMST - Output file/Record:Record1/TOUR-REC/O-NUMBER-ENTRIES and change its value from 6 to 14. Find O-TOTAL-EXPENSE and change its value from 7800 to 16900.
      Each cell is now in the Result Details mode. You can find more details about this option in Setting the format for test results.
      Edit values in test case editor 1
      Edit values in test case editor 2
  2. Generate the test case program.
    1. Click Generate.
      The test case editor prompts you to save your changes.
    2. Click Yes.
      The Generate test case programs window opens. You can view the list of the test case and stub programs that ZUnit generates from the source program.
    3. Check the Generate test case for main program check box. Select the Generate, build, and run test case radio button.
    4. Click OK.
      ZUnit generates the test case for the TOURFILE.cbl program. The Run As Test Case dialog opens.
    5. Select the Overwrite member check box for both the runner configuration file and the runner result file.
      Run As Test Case dialog
    6. Click OK.
    7. Click Locate Job or OK in the Job Submission dialog.
    The ZUnit test runner starts. TEST2 fails in O-TOTAL-EXPENSE of TOUR-REC. You can see that the discount is not working.
    Test2 failed
  3. To fix the error in the TOURFILE.cbl program:
    1. Open the source file in an editor.
    2. Comment out line 161, and uncomment line 162.
    3. Save the file.
    Discount should occur when W-NUMBER-ENTRIES is 10 or more, not more than 10.
    Fix error
  4. Submit <HLQ>.CNTL(TOURBLD) for compiling and linking the application. Check that the return code is 0000.
  5. Click Refresh from Source in the test case editor toolbar.
    Refresh from Source
    ZUnit test case editor is reopened for the updated TOURFILE.cbl file.
  6. Generate, build, and run the test case again as described in step 2.

Results

The ZUnit test runner starts and runs TEST1 - TEST2. The error in TOURFILE.cbl is fixed and the TEST2 test case has passed the run.
Test2 run passed
If you want to clean up the generated test cases and resources, see Cleaning up generated files.
Clean up generated files