Skip to content
Dave Nicolette edited this page Jan 8, 2015 · 20 revisions

Welcome to the cobol-unit-test wiki!

Design goals

  • Support fine-grained automated unit testing of Cobol programs (individual paragraphs).
  • Enable test-driven development of Cobol code targeted to the zOS platform in isolation from the mainframe (for instance, on a laptop).
  • Ensure source-level compatibility across zOS, Unix, Linux, and Windows platforms.
  • Require no modification of production code to enable unit testing.
  • Enable developers to write tests in plain vanilla Cobol, or at worst to learn special statements that follow familiar Cobol conventions.
  • Support batch main programs.
  • Support CICS programs.
  • Support called subprograms.

Setup

If you are loading this on a system configured using https://github.com/neopragma/provision-cobol-dev-ubuntu, then clone this repo as follows:

cd ~/projects
clone https://github.com/neopragma/cobol-unit-test

If you are configuring the software yourself, then start by installing GNU Cobol. I haven't set this up on any other platforms, so I can't help you with configuration issues that may arise. Ultimately you need GNU Cobol installed and then you can clone the repo.

A brief sample

           TESTSUITE 'CONVERT COMMA-DELIMITED FILE TO FIXED FORMAT' 

      *****************************************************************
      * COBOL COMMENTS ARE IGNORED SO YOU CAN DO THIS SORT OF THING IF
      * YOU PLEASE.
      *****************************************************************  

           MOCK FILE INPUT-FILE
           MOCK FILE   OUTPUT-FILE

           BEFORE-EACH
           MOVE FOO TO BAR
           MOVE ZERO TO WS-COUNT
           END-BEFORE

           AFTER-EACH
           INITIALIZE WS-RESULTS-TABLE
           END-AFTER

           TESTCASE      'IT CONVERTS TEXT FIELD 1 TO UPPER CASE' 
           MOVE 'something' TO TEXT-VALUE-1
           PERFORM 2100-CONVERT-TEXT-FIELD-1
           EXPECT TEXT-OUT-1 TO BE 'SOMETHING'

Notes

The precompiler recognizes certain keywords and substitutes test code, so that you need not code a lot of boilerplate code manually.

TESTSUITE - Provides a description for a series of test cases. The description is echoed in the output from the test run.

MOCK - declares a mock. Current version doesn't do anything with mocks. As a first step toward supporting mocks, the precompiler recognizes the MOCK keyword. This feature is currently under development. The initial focus is on mocking files in batch programs. Future plans include support for mocking EXEC CICS and EXEC SQL commands.

BEFORE-EACH, AFTER-EACH - the precompiler copies these statements into paragraphs that are performed at the start and end of each test case.

TESTCASE - identifies a test case. The description is echoed in the output of the test run.

EXPECT - asserts an expected result. Current version only supports an equality check for PIC X items.

The precompiler ignores Cobol-style comment lines.

Automated integration testing is out of scope

The framework doesn't address the case when we want to test a single step (executing a Cobol program) from a jobstream. It turns out to be fairly straightforward to set up test jobstreams using IBM utilities, in particular SuperC. This enables us to test single job steps in isolation on-platform.

If you need to automate the same level of testing off-platform, you can create fake input files and "expected" output files for your program, and then write a test script that populates the files appropriately, executes your program, and compares the actual and expected output files. You can use a diff utility or roll your own compare program or script. So, there's no need for a special framework to support functional testing.