Unit Test Assertion Failures Caused by Uninitialized Storage
COBOL does not initialize storage areas, by default. Therefore, unless explicitly initialized with a VALUE clause, COBOL data items may hold unpredictable values. Sometimes, this uninitialized data is saved into a test case stub when a unit test is generated. As a result, a unit test may report assertion failures due to unpredictable data.
For example, a file output record or a sub-program argument may include data originating from an uninitialized working-storage field. An assertion failure will likely occur when actual data from a test run is compared to this expected, but "random," baseline data.
Note, too, that uninitialized storage may be returned as an argument of a called sub-program. For example, an assembler sub-program, called to obtain storage to be mapped by a linkage section structure, may return uninitialized storage to the COBOL program.
To better manage unit test results, do one of the following:
- If site coding standards allow, initialize COBOL data items with a VALUE clause or with a MOVE statement.
- Edit the unit test's interfaces so that fields having unpredictable data are marked Usage "in" or "none."
Alternatively, for such fields, edit individual assertion comparison operators to be "noassert" in the stub itself. - Finally, when running a unit test, it is recommended that Language Environment run-time option STORAGE(00,00,00) be used. This is included, by default, in the provided Test Runner JCL template's CEEOPTS DD SYSIN statement. This ensures run-time heap and stack storage is set to LOW VALUES before the target program is run, most closely emulating the initial state of a batch main COBOL program.