Using the sample

To use the Enterprise COBOL AZUTC001 sample, configure the test runner, submit the test runner JCL, and view the results.

  1. To open the ZUnit test runner configuration file in the ZUnit Test Runner Configuration editor, double-click <HLQ>.ZUNIT.AZUCFG(AZUCF001). The editor opens and shows that only one test case is run by using this configuration: Test case AZUTC001.
  2. Select ZUnit runner and look at the Runner continuation settings. The continuation settings instruct the test runner to attempt to continue despite any failures or errors that occur.
  3. Submit the JCL <HLQ>.CNTL(ZUNIT001) and monitor job ZUNIT001.
  4. Because test AZUTC001.test003 is expected to fail with an assertion, job ZUNIT001 finishes with a return code of U0004. The ZUnit test runner can set the following return codes:
    • U0000: All tests passed.
    • U0004: One or more tests failed with an assertion.
    • U0008: One or more tests are in error (for example, SOC4, DIV/0).
    • U0016: A severe error occurred (for example, file I/O error).
  5. The output of job ZUNIT001 contains output from the following programs:
    • The ZUnit test runner. This output is marked by  1  in the sample output.
    • The ZUnit test case AZUTC001.cbl, marked by  2  in the sample output.
    • The ANAGRAM.cbl program, marked by  3  in the sample output.
     1  ZUnit Test Runner 1.0.0.0 started at 2012-04-18T19:44:14.391...
     1  AZU1003S The Test "AZUTC001.test003" failed due to an assertion. The user-1:supplied text "ANAGRAM failed to detect that Snooze alarms
     1   is an anagram of Alas! No more Zs" is associated with the assertion. The 1:Test is a member of Test Case module "AZUTC001" which has
     1  a name of "AZUTC001 Test Case written in COBOL" and a UUID of "e3a227e2-1:cd9e-4418-81b9-c4863ab3af3b".
     1   o Test count: 4
     1   o Tests passed: 3
     1   o Tests failed: 1
     1   o Tests in error: 0
     1  ZUnit Test Runner 1.0.0.0 ended at 2012-04-18T19:44:14.487.
     2  AZUTC001.test001 Started...
     3  ANAGRAM STARTED...
     3  o FIRST-WORD:Eleven plus two.
     3  o WORD-BUF-1:WVUTSPONLLEEE .
     3  o SECOND-WORD:Twelve plus one.
     3  o WORD-BUF-2:WVUTSPONLLEEE .
     3  o RESULT=Y.
     3  ANAGRAM SUCCESSFUL
     2  AZUTC001.test001 Successful.
     2  AZUTC001.test002 Started...
     3  ANAGRAM STARTED...
     3  o FIRST-WORD:The Morse code.
     3  o WORD-BUF-1:TSROOMHEEEDC .
     3  o SECOND-WORD:Here come dots.
     3  o WORD-BUF-2:TSROOMHEEEDC .
     3  o RESULT=Y.
     3  ANAGRAM SUCCESSFUL
     2  AZUTC001.test002 Successful
     2  AZUTC001.test003 Started...
     3  ANAGRAM STARTED...
     3  o FIRST-WORD:Snooze alarms.
     3  o WORD-BUF-1:ZSSROONMLEAA .
     3  o SECOND-WORD:Alas! No more Zs.
     3  o WORD-BUF-2:ZSSROONMLEAA! .
     3  o RESULT=N.
     3  ANAGRAM SUCCESSFUL
     2  AZUTC001.test004 Started...
     3  ANAGRAM STARTED...
     3  o FIRST-WORD:Astronomer.
     3  o WORD-BUF-1:TSRROONMEA.
     3  o SECOND-WORD:Moon starer.
     3  o WORD-BUF-2:TSRROONMEA .
     3  o RESULT=Y.
     3  ANAGRAM SUCCESSFUL
     2  AZUTC001.test004 Successful
  6. To open the ZUnit test runner results file in the ZUnit Runner Results editor, double-click <HLQ>.ZUNIT.AZURES(AZURS001) .
  7. Expand Test case AZUTC001 and select Test AZUTC001.test003. As expected, the results show that this test failed.
  8. Expand all nodes under Test AZUTC001.test003 and select Exception message number (1003), Severity (2), Component code (AZU). The message indicates that the cause for the failure is an assertion. Assertions and errors are both Language Environment® exceptions, except that assertion exceptions are intentionally created to end a test when the test writer determines that the actual behavior of the program under test (ANAGRAM.cbl) does not match its expected behavior.
    AZU1003S The test "AZUTC001.test003" failed due to an assertion. 
    The user-supplied text "ANAGRAM failed to detect that Snooze alarms is an anagram of Alas! No more Zs" is associated with the assertion. 
    The test is a member of test case module "AZUTC001" which set a test case name of "AZUTC001 Test Case Written In COBOL" and an id of "9feb6a09-faf7-4b83-85b4-75664938e53f" when initialized.
  9. Select Traceback entry point (TEST003). The traceback information assists with locating the origin of the failure (assertion). The traceback shows that the AZUASTFM (fail with message) ZUnit assertion API was started in entry point TEST003 at statement 623.
  10. Open the compiler listing for program AZUTC001.cbl and locate the call to AZUASTFM (fail with message) at statement 623 in entry point TEST003:
    1PP 5655-S71 IBM Enterprise COBOL for z/OS 5.2.0
    000556  IDENTIFICATION DIVISION.
    000557  PROGRAM-ID. 'TEST003'.
    000558  DATA DIVISION.
    000559  WORKING-STORAGE SECTION.
    000560  1 FAIL-MESSAGE-TXT PIC X(254).
    000561  1 FAIL-MESSAGE-LEN PIC S9(9) COMP-5.
    000562  LINKAGE SECTION.
    000563  COPY ANAGRAM.
    ...
    000595  1 TEST-CASE-PTR    POINTER.
    000596  1 TEST-FIXTURE-PTR POINTER.
    000597  1 TEST-NAME-PTR    POINTER.
    000598  1 TEST-NAME-LEN    PIC S9(9) COMP-5.
    000599  1 TEST-NAME        PIC X(254).
    000600  PROCEDURE DIVISION USING BY VALUE TEST-CASE-PTR
    000601                     BY VALUE TEST-FIXTURE-PTR
    000602                     BY VALUE TEST-NAME-PTR
    000603                     BY VALUE TEST-NAME-LEN.
    000604 *    display test name on entry
    000605      SET ADDRESS OF TEST-NAME TO TEST-NAME-PTR
    000606      DISPLAY TEST-NAME(1:TEST-NAME-LEN) ' Started...'
    000607 *    establish addressability to test fixture
    000608      SET ADDRESS OF ANAGRMIO TO TEST-FIXTURE-PTR
    000609 *    test a valid anagram
    000610      CALL 'ANAGRAM' USING ANAGRMIO
    000611      IF NOT-ANAGRAM OR INPUT-ERROR
    000612         MOVE 1 TO FAIL-MESSAGE-LEN
    000613         STRING
    000614            'ANAGRAM failed to detect that '
    000615            FIRST-WORD(1:FIRST-WORD-LEN)
    000616            ' is an anagram of '
    000617            SECOND-WORD(1:SECOND-WORD-LEN)
    000618            DELIMITED BY SIZE INTO FAIL-MESSAGE-TXT
    000619            WITH POINTER FAIL-MESSAGE-LEN
    000620         END-STRING
    000621         SUBTRACT 1 FROM FAIL-MESSAGE-LEN
    000622 *       throw an assertion exception (ends test)
    000623         CALL 'AZUASTFM' USING BY VALUE TEST-CASE-PTR
    000624                         BY REFERENCE FAIL-MESSAGE-TXT
    000625                         BY VALUE FAIL-MESSAGE-LEN
    000626         END-IF
    000627 *    display test name on exit
    000628      DISPLAY TEST-NAME(1:TEST-NAME-LEN) ' Successful.'
    000629      .
    000630   END PROGRAM 'TEST003'.