Using Z Validation Assistant

Generate JUnit tests for a Java™ service that has been transformed from COBOL by using IBM® watsonx Code Assistant for Z Validation Assistant (Z Validation Assistant). This tool helps you to ensure that the Java is semantically equivalent to the COBOL, so you can be confident that you have a good starting point for any future development.

Running Z Validation Assistant

The Z Validation Assistant process consists of two steps that must be completed in order. First, you need to generate the COBOL test data. Second, you need to test the Java methods for equivalence. Complete the previous steps in the watsonx Code Assistant for Z process before performing these steps.

Setting up the COBOL for testing

As a prerequisite to using Z Validation Assistant, compile and link to build the refactored COBOL program with TEST(DWARF) provided as a compiler option.

Z Validation Assistant will need:
  1. The compiler listing of the built program that is imported into the VS Code COBOL project as a text file (non-binary).
  2. Knowledge of the location of the Load Library of the binary program that results from the build process.

Generate the COBOL Test data

  1. In the Explorer panel, change the listing file extension so that it ends with .log.
  2. Right click the listing file and select watsonx Code Assistant for Z Validation Assistant > Generate COBOL Outputs.
    Figure 1. Example Screenshot of Selecting Generate COBOL Outputs
    An example screenshot showing the menu of where to select watsonx Code Assistant for Z Validation Assistant > Generate COBOL Outputs.
  3. In the input field, enter your load library and press Enter.
    Figure 2. Example Screenshot of Entering Load Library Location
    An example screenshot of entering the load library location in the input field.

    Status notifications appear in the lower right of the screen that indicates the progress of the generation.

  4. Files with test data are created in the Explorer bar within the .validate folder.
  5. After the process is complete, the following message is displayed: Completed Cobol Output Generation.
    Figure 3. Example Output of Completed COBOL Output Generation
    Awaiting Program Load Library location input ...
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    Starting Generate COBOL Outputs...
    Generating COBOL file from listing...
    Retrieving Program Validation Information...
    Parsing COBOL for test generation...
    Executing paragraph-based test input generation...
    Executing Script Generator...
    WARNING: No encoding was set in Zowe Configuration. Using default encoding: IBM-1047
    Creating and Submitting JCLs...
     * Job ID [JOB00535] finished.
     * Job ID [JOB00534] finished.
     * Job ID [JOB00536] finished.
     * Job ID [JOB00537] finished.
     * Job ID [JOB00538] finished.
     * Job ID [JOB00541] finished.
     * Job ID [JOB00543] finished.
     * Job ID [JOB00540] finished.
     * Job ID [JOB00542] finished.
     * Job ID [JOB00539] finished.
    Processing Job Data...
     * Processing Job Data [LGACDB01_MAINLINE_FIRST_SENTENCES-testdata.json]
     * Processing Job Data [LGACDB01_MAINLINE_INSERT-CUSTOMER-testdata.json]
     * Processing Job Data [LGACDB01_MAINLINE_MAINLINE-EXIT-testdata.json]
     * Processing Job Data [LGACDB01_MAINLINE_Obtain-CUSTOMER-Number-testdata.json]
     * Processing Job Data [LGACDB01_MAINLINE_WRITE-ERROR-MESSAGE-testdata.json]
    
    Paragraph: INSERT-CUSTOMER OF MAINLINE
     * 4 Test Paths
       * Program Outputs: 4/13 filled
       * Resource Outputs: 20/38 filled
    
    Paragraph: Obtain-CUSTOMER-Number OF MAINLINE
     * 2 Test Paths
       * Program Outputs: 0/10 filled
       * Resource Outputs: 0/0 filled
    
    Paragraph: WRITE-ERROR-MESSAGE OF MAINLINE
     * 3 Test Paths
       * Program Outputs: 20/20 filled
       * Resource Outputs: 3/3 filled
    
    Completed COBOL Output Generation.

Test the Java Methods for Equivalence

  1. In VS Code, open the Java file under the java_output folder that contains the method to be tested.
  2. Highlight the name of the method to be tested.
  3. Right click the highlighted method name and select watsonx Code Assistant for Z Validation Assistant > Run Equivalence Test.
    Figure 4. Screenshot of Selecting Run Equivalence Test
    A screenshot of the menu to click watsonx Code Assistant for Z Validation Assistant > Run Equivalence Test.
  4. The progress of the tests output to the Terminal window of VS Code. More detailed results can be found in the IBM watsonx Code Assistant for Z Validation Assistant panel at the lower left of the screen. This panel lists the generated Java programs with their methods and the tests for each method.

    After the process is complete, the following message is displayed: Equivalency Tests Complete.

    Figure 5. Example Output of Completed Java Equivalence Test
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    Java Class: <CaCustomerRequest>
    Java Method: <mainlineInsertCustomer>
    Java Package: <com.ibm.wcaz>
    Project Name: <LGACDB01>
    Program Name: <LGACDB01>
    Cobol URI: <file:///Users/user/Downloads/demo/Cobol%20Programs/LGACDB01.cbl>
    Java URI: <file:///Users/user/Downloads/demo/generated_java/com/ibm/wcaz/CaCustomerRequest.java>
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    Testing Semantic Equivalence:
    Retrieving Method Validation Information...
     * Getting COBOL outputs from: /Users/user/Downloads/demo/.validate/LGACDB01/debugger/output/values/LGACDB01_MAINLINE_INSERT-CUSTOMER-testdata-values.json
    Preparing Java Files...
    Creating JUnit Comparison Tests...
    Compiling...
    Running Tests...
    Equivalency Tests Complete.

    Tests that have passed are marked with a and tests that have failed are marked with an X.

    Figure 6. Example Screenshot of Passed Tests
    An example screenshot showing check marks to indicate passed tests.
  5. To export the Java equivalence test, left click the diskette icon with the tooltip Export Java Test.
    Figure 7. Screenshot of Exporting Java Test
    A screenshot of the Export Java Test icon.

    The progress of the export outputs to the Terminal window of VS Code.

    After the process is complete, the following message is displayed: Java test export complete.

    Figure 8. Example Output of Completed Java Export Test
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    Java test export starting...
    Exporting Java tests for com.ibm.wcaz.CaCustomerRequest ...
     ...exported junit_test/LGACDB01/com/ibm/wcaz/CaCustomerRequest$insertCustomerTests.java as a Java test for com.ibm.wcaz.CaCustomerRequest.
     ...exported junit_test/LGACDB01/com/ibm/wcaz/CaCustomerRequest$mainlineInsertCustomerTests.java as a Java test for com.ibm.wcaz.CaCustomerRequest.
    Supplying IBM watsonx Code Assistant for Z Validation Assistant mockz libraries...
     ... supplied IBM watsonx Code Assistant for Z Validation Assistant mockz libraries at junit_test/LGACDB01/lib/mockz
    Supplying dependent test and mocking libraries...
     ... supplied dependent test and mocking libraries at junit_test/LGACDB01/lib/mocking
    Java test export complete.