Mocking and Stubbing Programs Containing EXEC Statements

Programs that contain EXEC statements (such as EXEC SQL) can often be tricky to test. There is an additional overhead required to support these statements, and keep the test run executing. However, you can enable support in the MFUPP preprocessor to ignore any EXEC statements when the test is run.

Taking an SQL program as an example, you can replace any EXEC SQL statements with your own portions of mocked code. This code often replaces complex code or processes with simplified code aimed at supplying the test case with what it needs to test.

Support for this is enabled using the MOCK, and the SQL directives (note, EXEC SQL support is not currently, fully implemented). Additionally, the EXEC-REPORT-FILE directive also allows you to catalog the EXEC statements in your source code. This catalog file can then be used to generate snippets of code that form the stubs for the mocked code.

The snippets (.cpy files) are generated using the generate-exec-mock-snippet option of the test runner. There are a number of parameters you can specify to this option that determine the information added to the stub code within these files.

As with any mocked code, a controller - MFU-MD-EXEC-CONTROLLER - is required to pass the flow of execution to the stubbed code whenever an EXEC statement is hit. If you use the catalog file to generate the stubbed code, the controller is created in the MFUM_<program-name>.cpy file, and (depending on the options supplied when the snippets were generated) it also contains a number of sections corresponding to the individual EXEC statements in the source code.

Tip: The EXEC statements within the catalog file and the mocked code are each given a unique reference code. If you would like to use more user-friendly references for these statements/sections, you can specify your own identifiers: in the source code, insert a comment line preceding the EXEC statement. For example:

    *> MFUPP-SID MY-SQL-COMMIT
    EXEC SQL COMMIT
    END-EXEC

When the file is next cataloged (using the EXEC-REPORT-FILE directive), the new identifiers are used throughout the tests.