Skip to content

Approach to Mocks

Dave Nicolette edited this page Jan 29, 2021 · 28 revisions

Home -> Development Guide -> Implementation Notes ->

As of January 2021, support for mocks has not been implemented in Cobol Check.

We want to take a slightly different approach than was taken in the proof of concept project, cobol-unit-test. In that project, a mock represented behavior, such as reading a file or calling a subprogram. In Cobol Check, a mock represents (or will represent) an external resource - a file, a subprogram, etc. - and the user can specify one or more behaviors for that resource. We expect this approach to be easier for users and less error-prone than the previous approach.

Here are some examples of how users might code Mocks in Cobol Check (subject to change as development continues).

Mocking a batch input file and specifying behaviors for particular operations

Hypothetical scenario: A batch update of taxpayer information for a government agency that processes tax returns. We want to check that the program populates the correct "error code" values (as defined for that application) when the inbound sequential update file is not found, and another case when an input record doesn't have a postal code for the taxpayer's street address.

    TestCase "It handles file-not-found"
        mock Taxpayer-Update-File
          on open file-status is file-not-found 
        end-mock
        perform 1100-open-files 
        expect w-error-code to be "TUFNOTFND" 

    TestCase "It handles missing postal code" 
        mock Taxpayer-Update-File 
          on read 
              move "testID123" to tp-in-taxpayer-id 
              move "55 main st." to tp-in-taxpayer-addr1 
              move "bakersfield, ca" to tp-in-taxpayer-addr2 
              move spaces to tp-in-taxpayer-postcode 
        end-mock 
        perform 1500-validate-in-rec 
        expect ws-error-code to be "TUFNOPOST" 

Mocking a CICS resource and specifying behaviors for specific operations

Clone this wiki locally