I hope part 1 helped you get started with zUnit and if you now have questions on how to use it with call statements, copybooks, DB2, DCLGEN and QSAM input/output datasets then you are ready for part 2.

Here is the agenda for this part 2:



And again if you want to learn more about zUnit then sign up for an IBM class and contact jsayles@us.ibm.com for the schedule

The program


My test program in this part 2 is a COBOL program that

  • reads a table name from a sequential dataset (INDD1)
  • then selects the table in SYSTABLES

With zUnit, I will test that the creation date of the table (CREATEDTS) is what I expect.

My program uses a DCLGEN copybook SYSTBL and also a static call to another program “PGEND” just to show how to test it with zUnit.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. DB2QSAM1.
      *****************************************************************
      *                                                               *
      *   Simple COBOL with DB2 and QSAM file                         *
      *   - read value from sequential dataset                        *
      *   - find table in systables using value above                 *
      *                                                               *
      *****************************************************************
      /
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT  SECTION.

       FILE-CONTROL.
           SELECT  INPUT-FILE1           ASSIGN TO INDD1.

       DATA DIVISION.
       FILE SECTION.
      * Input file containing 2 lines:
      * table name
      * length of table name
       FD  INPUT-FILE1
           LABEL RECORDS ARE STANDARD
           BLOCK CONTAINS 0 RECORDS
           RECORDING MODE F.
       01 INPUT-REC.
           05 VALUETXT1 PIC X(80).

       WORKING-STORAGE SECTION.
         EXEC SQL INCLUDE SQLDA END-EXEC.
         EXEC SQL INCLUDE SQLCA END-EXEC.

       77  PGM-NAME         PICTURE X(8).

       LINKAGE SECTION.
      * DCLGEN TABLE(SYSIBM.SYSTABLES)
       01 RCV-PARMS.
          EXEC SQL INCLUDE SYSTBL END-EXEC.

      /

       PROCEDURE DIVISION USING RCV-PARMS.
       MAIN.
           DISPLAY "Entering DB2QSAM1"

           initialize TBL-NAME.

           PERFORM 10-READ-INPUT THRU 10-EXIT.

           PERFORM 20-READ-SYSTABLES THRU 20-EXIT.

           PERFORM 30-FINISH THRU 30-EXIT.

           DISPLAY "End DB2QSAM1"

           GOBACK.

      **************************************
       10-READ-INPUT.
           DISPLAY "Read input file"
            OPEN INPUT  INPUT-FILE1
            READ INPUT-FILE1
            MOVE VALUETXT1 to NAME-TEXT
            DISPLAY "NAME-TEXT=" NAME-TEXT "<"
            READ INPUT-FILE1
            DISPLAY "VALUETXT1=" VALUETXT1 "<"
            COMPUTE NAME-LEN = FUNCTION NUMVAL(VALUETXT1)
            DISPLAY "NAME-LEN=" NAME-LEN "<"
            CLOSE INPUT-FILE1
            .
       10-EXIT.
            EXIT.

      **************************************
       20-READ-SYSTABLES.
           DISPLAY "Select in SYSTABLES"
           EXEC SQL
            select CREATEDTS into :CREATEDTS
            from sysibm.systables
            WHERE NAME=:TBL-NAME
            FETCH FIRST 1 ROW ONLY
           END-EXEC.

           DISPLAY "CREATEDTS=" CREATEDTS "<"
           .
       20-EXIT.
            EXIT.

      ***************************************
       30-FINISH.
           MOVE "DB2QSAM1" TO PGM-NAME.
           call "PGEND" USING PGM-NAME
           .
       30-EXIT.
            EXIT.


       END PROGRAM DB2QSAM1.


Customized zUnit JCL proc for DB2


The AZUZUNIT JCL procedure shipped with RDz 9.5.1 is only suitable for non DB2 batch runs. To test a DB2 program, I use the following procedure:

//*********************************************************************
//* Rewrite of ELAXFTSO for zUNIT DB2 testcases                       *
//*                                                                   *
//*********************************************************************
//AZUZUNIT PROC XMLPRFX='SYS1',
//            CSSPRFX='SYS1',
//            LIBPRFX='CEE',
//            LODPRFX='CUST.V95.HHOP951',
//            AZUCFG=NULLFILE,
//            AZURES=NULLFILE,
//            AZULOD=NULLFILE
//*
//TSOGO    EXEC PGM=IKJEFT01,REGION=0M
//STEPLIB  DD DISP=SHR,DSN=&XMLPRFX..SIXMLOD1
//         DD DISP=SHR,DSN=&CSSPRFX..CSSLIB
//         DD DISP=SHR,DSN=&LIBPRFX..SCEERUN
//         DD DISP=SHR,DSN=&LIBPRFX..SCEERUN2
//         DD DISP=SHR,DSN=&LODPRFX..SFELLOAD
//         DD DISP=SHR,DSN=&LODPRFX..SFELAUTH  * integrated debugger
//         DD DDNAME=AZULOD
//         DD DISP=SHR,DSN=DB2.V9R1M0.SDSNLOAD
//         DD DSN=USER182.ZUNIT.COBOL.LOAD, * testcases + programs
//            DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
//SRCPGM   DD DUMMY
//AZULOD   DD DISP=SHR,DSN=&AZULOD
//AZUCFG   DD DISP=SHR,DSN=&AZUCFG
//AZURES   DD DISP=SHR,DSN=&AZURES
//SYSTSIN  DD DUMMY
//*
//RUN      EXEC PGM=IEFBR14
//*


Configure the property group


Same as in part1 with the following modification:

  • Add DB2 support
  • Add DB2 support
    Add DB2 support
  • Add copybook library to find the DCLGEN for SYSTABLES
  • add copybook library
    zUnit, add copybook library
  • Modify your JCLLIB ORDER to find the customized AZUZUNIT first
  • JCL PROCLIB
    JCL PROCLIB
  • Add your DB2 plan to the zUnit SYSTSIN DD
  • zUnit DB2 Plan
    zUnit DB2 Plan


Build the program to be tested


Remember that zUnit does not build your program but the generated testcases. Your program needs to be built before.
Here are the JCLs and joblogs of the compile and link of my programs with DB2 v11: DB2QSAM1 and PGEND

DB2QSAM1.build.txt
DB2QSAM1.jcl
PGEND.cbl
PGEND.jcl
PGEND.build
SYSTBL.cpy


Create test data


From RDz z/OS Explorer:

  • create a MVS subproject
  • add program DB2QSAM1.cbl to it
  • right-click on it and select menu z/OS Automated Unit Testing Framework (zUnit) > Generate Test Case
  • zUnit part2 generate test case

  • click on Edit Test Entry Data
  • zUnit part2 generate

  • during first import or when copybooks have been modified, check dependency again
  • zunit.part2.generate3

  • Add values for the input sequential dataset: SYSTABLES and a length of 9 characters
  • (Note that the wizard is initially opened with only one record (for the table name) so you need to add one record to be able to enter the length of the table name)

  • Add value for the static call: DB2QSAM1
  • zunit.part2.data2

  • Add value for the expected creation date of SYSTABLES: 2014-01-31-08.14.58.574284
  • zunit.part2.data1


Generate and build the test case


  • Click on the Generate Programs icon on the Test Entry Data Editor
  • zunit.part2.build1

  • Click OK and testcase is generated
  • Click OK to compile and link it: a JCL is automatically submitted
  • zunit.part2.build2
    zunit.part2.build3

  • We can now run the testcase
  • zunit.part2.run1


Run the test case


  • Check to override if needed and click OK on the “Run as Testcase” wizard dialog
  • zunit.part2.run2

  • A job is submitted. Click on Locate to find it automatically on the Remote System Explorer
  • zunit.part2.run3

  • Result of the test is shown
  • zunit.part2.run4

  • JOB log of the run shows
  • zunit.part2.run5


Sequential dataset created


As you may have noticed in this scenario, zUnit has created the input sequential dataset for you based on your property group settings and has populated it with the test entry data specified earlier.
zunit.part2.propgrp4

zunit.part2.seqdataset

20 comments on"Getting started with RDz zUnit – Part 2 – Olivier/IBM"

  1. Hi Olivier
    Thank you for this post which is very informative. I work with Accenture on a project with SSA where RDz 9.1.3 is installed. When I tried a DB2 cobol program to generate test case, it is showing error that ‘SQLCA’ is not defined in the data division. The program has SQLCA defined in the data division. Any thoughts why this error is coming up. Thank you. The program compiled and bound good.

    • Olivier Gauneau August 16, 2016

      Hi Subba,

      Thanks for your comment !
      As discussed, I will be assisting you on the PMR you have opened if needed.

  2. I’m using IDz v14 and I’m having trouble trying to link ZUTFIN01. I get the message: “SYMBOL AZUASTFM UNRESOLVED. MEMBER COULD NOT BE INCLUDED FROM THE DESIGNATED CALL LIBRARY”.

    Which library should contain that member? The only AZ* members that I see in our SFELLOAD library are the following:
    AZUCLCNV
    AZUMENG
    AZUMSGT
    AZUMUEN
    AZUTSTRN
    should there be others?

    Can you share the JCL that you used to link ZUTFIN01?

    By the way, the article does not even mention ZUTFIN01 – it was generated during the “Generate and build the test case” phase

    Thanks

    • Ah, I may have figured it out – if I use the following link parms then it links OK: (‘DYNAM(DLL)’,’NOREUS’)
      Of course the link also needs INCLUDE AZUTSTRX

      • I am getting the same error for inking PL/I Program, these link parms DYNAM(DLL)’,’NOREUS’ does not resolve the linking of PL/I program. Can some one assist.

  3. Hi Olivier

    I’m using IDz v14 and I want to download all test data.
    When I use generating test case, Even if I create more than one ENTRY, only 1 ENTRY is output.
    How can I output all ENTRY?

  4. Hi Olivier

    I would like to check test scenarios and test results that someone created with zUnit.

    Please tell me how to import / export other person’s test scenarios and test results in zUnit.

  5. If we are defining a file item with WORKING STORAGE SECTION and try unit test with zUnit, the item definition of WORKING STORAGE SECTION will not be displayed in the test case. Only the definition of FILE SECTION is displayed.
    In this case, can we create a test case reflecting the item definition of WORKING STORAGE SECTION in zUnit? If not, there is alternative ways?

  6. Hi Oliver,
    I am facing some weird issue where testcase is going in error instead of pass/fail. Did you face any such issue?
    Any help will be appreciated.
    Thanks,
    Mahak

  7. Neena Sharon June 20, 2018

    Hello

    Will I be able to import the values for my test inputs and expected output from an Excel sheet or do I have to manually type in the values for every entry?

    Thanks,
    Neena.

  8. Paulo Nayan July 20, 2018

    Hi Oliver,
    In the zUNIT tab (Additional JCL) you are running AZUTSTRN using the PLAN(OGAPLN1). Did you BIND the AZUTSTRN into this plan (OGAPLN1) ?

    • Olivier Gauneau July 20, 2018

      Hi Paulo,

      No I did not.
      AZUTSTRN has no DB2 calls. It just calls the generated testcase module which calls your program.

      • Paulo Nayan July 20, 2018

        Mr Gauneau,

        Sorry my low understanding about DB2, but I don’t understand why a program (AZUTSTRN) which hasn’t DB2 call is running this way:
        //TSO.SYSTSIN *
        DSN SYSTEM(DSNB)
        RUN PROGRAM(AZUTSTRN)
        PLAN(OGAPLN1)
        LIB(‘INSTALL…..

        In this case, I have to BIND the program AZUTSTRN in the plan (OGAPLN1), haven´t I ? And to BIND some program I think it is necessary thist program has at least one EXEC SQL, do you agree ?

        • Olivier Gauneau July 25, 2018

          Hi Paulo,

          If someone is not a DB2 or even COBOL development expert then it is me 🙂

          The plan is not for AZUTSTRN but for your program so on this example it is for DB2QSAM1, see https://developer.ibm.com/mainframe/wp-content/uploads/sites/46/2016/05/DB2QSAM1.build_.txt
          BIND PACKAGE(MVS011DB.GAUNEA2)
          MEMBER(DB2QSAM1) LIBRARY(‘GAUNEA2.ZUNIT.DBRMLIB’) ACTION(REP) VALIDATE(BIND)

          AZUTSTRN (zUnit runner load module) will call TDB2QSAM (generated testcase) which will call DB2QSAM1 (program to test).

          Make sense?

          All the best,

          Olivier

  9. Shalini Gupta January 21, 2019

    Hi Olivier,

    I am trying to test a simple cobol-DB2 program which using the steps mentioned above on your blog. However i am facing issue:

    An error occurred while opening the test entry data.
    Possible reasons for failure:
    1.Syntax errors were found in the source. If the file is from the workspace,check the ‘Remote Error List’ view for the list of errors.
    2. PSD2PGM.cbl is expected to be a complete COBOL program,based on its file extension. You can change the file extension support by going to the “More COBOL options ” tab of the COBOL importer preference page.
    PSD2PGM.cbl(26)IGYLI0049-S The “Copy” library was not found. Skipped to the the period terminating the “COPY” statement.

    My cobol code is present on the remote system and i have successfully compiled my code for zUnit without any syntax error.
    Also, the copy library is mentioned in the SYSLIB option of the property group used for compilation and zUnit.

    Please suggest.

  10. Paulo Nayan January 22, 2019

    Hi Olivier,
    In my RDz I have two Property Groups: one for COBOL/BATCH and other for COBOL/DB2. I created two procedure zUNIT for each one: AZUZUNIT (batch) and AZUNITDB (DB2).
    In JCLLIB I used .PROCLIB1 which has both procedures (AZUZUNIT and AZUNITDB).
    In tab zUNIT at the property group for DB2 I changed the procedure name from AZUZUNIT to AZUNITDB and the RDz has accpeted.
    But when I try to run the test case I got an JCL error because the RDz generated a JCL using the procedure AZUZUNIT.
    ==> RUNNER EXEC PROC=AZUZUNIT.
    How can I change it forever ? Can’t I have two or more procedures to use zUNIT ?

Join The Discussion

Your email address will not be published. Required fields are marked *