-
Notifications
You must be signed in to change notification settings - Fork 29
Lessons about Mocks from the Proof of Concept
Home -> Developer Guide ->
As of this writing, cobol-check does not yet support mocks at all. The current stage of development is to re-implement the basic functionality of the proof of concept project. In some areas, we are implementing the functionality differently than the proof of concept, due to lessons learned. Support for mocks is one of those areas.
The proof of concept has some issues with respect to mocking files in batch mode. The main issue is storage allocation for file record areas. If the program under test reads a file directly into the area defined in File Control, then storage for that area is allocated when the file is opened. Running the program off-platform, when we mock the file it is never really opened. Memory for that area may or may not be allocated, depending on the compiler. When running on-platform, we know the storage will not be allocated when we mock the file.
Cobol-check must implement batch file mocks in a way that ensures we have storage allocated for record areas.
For mocks of CICS commands, the proof of concept tries to identify the specific command by looking at all the arguments. This has proven to be a clumsy way to handle it. Cobol-check will mock the CICS resource, and then allow the user to specify behavior for each access to that resource using syntax like this:
* This mocks every EXEC CICS READ DATASET command for dataset 'foo'
MOCK DATASET 'foo'
ON READ
MOVE...
MOVE...
SET...
etc.
END-MOCK
* You can specify conditions to be raised
MOCK DATASET 'foo'
ON READ
CONDITION IS NOTFND
ON WRITE
CONDITION IS DUPREC
END-MOCK
* You can use less-verbose syntax if you prefer
MOCK DATASET 'foo'
ON READ CONDITION NOTFND
ON WRITE DUPREC
END-MOCK
* This mocks EXEC CICS READ DATASET 'foo' with a specific key value specified in RIDFLD
MOCK DATASET 'foo'
ON READ RIDFLD('keyvalue')
MOVE...
MOVE...
SET...
etc.
END-MOCK
* This mocks EXEC CICS READNEXT DATASET 'foo'
* Note EXEC CICS STARTBR DATASET 'foo' is also stubbed, because
* the resource 'foo' is the thing mocked, not just the READNEXT call.
MOCK DATASET 'foo'
ON READNEXT RIDFLD(WS-FOO-KEY)
MOVE...
MOVE...
SET...
etc.
END-MOCK