• Stars
    star
    106
  • Rank 325,791 (Top 7 %)
  • Language
    COBOL
  • License
    GNU General Publi...
  • Created about 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unit testing framework and sample code for batch Cobol programs.

Cobol unit testing framework for mainframe programs

The goal of the project is to enable isolated unit testing of individual paragraphs in Cobol programs in a standalone environment with no connection to a zOS system.

Please see the wiki for more information.

Update December 2020

Having ignored this project for some time, I recently learned there were several pull requests that had been languishing for months. Sorry about that!

When I merged the changes, I discovered they broke the tool on Linux with Gnu COBOL. There is a set of sample test cases that should be executed to ensure functionality that worked before still works after applying changes to the code.

The modified version with changes by Rune Christensen and his team is available here: https://github.com/Rune-Christensen/cobol-unit-test. I think that version works on zOS. The present version here does not.

Beyond that, however, I think that it would be useful to rewrite this tool using a language better suited to text processing. This is a proof-of-concept project, and was never polished. It is somewhat useful, but there are many holes in it.

My original idea to write the tool in Cobol was to try and achieve cross-platform support. That didn't work out. I would like the tool to work on Linux, Unix, Windows, and zOS, and possibly OS X if there's a way to set it up so that it's hassle-free for developers. Gnu Cobol on OS X isn't hassle-free IMO. To that end, I'm thinking of Java for the rewrite, even though I can think of half a dozen other languages better suited to text processing. Java is a first-class citizens on all the platforms of interest.

Let me know if you're interested in contributing to such a rewrite.

Description

The unit test precompiler copies the program under test and inserts test code into the WORKING-STORAGE SECTION and PROCEDURE DIVISION. You can then run the copy of the program, which executes the isolated unit test cases without running the program from start to finish.

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.
      *****************************************************************  

           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'

           TESTCASE 'IT HANDLES FILE NOT FOUND GRACEFULLY'
               MOCK
                   FILE INPUT-FILE 
                   ON OPEN STATUS FILE-NOT-FOUND
               END-MOCK    
               PERFORM 0100-OPEN-INPUT
               EXPECT WS-INPUT-FILE-STATUS TO BE '35'
               EXPECT WS-FRIENDLY-MESSAGE TO BE 'SORRY, COULDN''T FIND INPUT-FILE'

Notes

The precompiler recognizes certain keywords and substitutes test code, so that you need not code a lot of boilerplate code manually. Please see the wiki for syntax details.

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 has support for mocking EXEC CICS commands and rudimentary support for mocking batch file I/O. This feature is currently under active development.

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 supports PIC X, numeric, and 88-level compares.

VERIFY - verifies that a mock was accessed the expected number of times.

The precompiler ignores Cobol-style comment lines.

Examples

Copy the envvars file and update the PROJECT variable: cp envvars.example envvars

Compile the program SAMPLE, located at src/main/cobol/SAMPLE.CBL

./compile SAMPLE

Run the unit tests for SAMPLE. Configuration file is src/test/resources/SAMPLEC and unit tests are in src/test/cobol/unit-tests/SAMPLET.

./run-ut SAMPLEC SAMPLE SAMPLET

Run all the provided examples.

./run-examples

The sample programs are:

  • CALLDEMO - demonstration of testing a called subprogram.
  • CICSDEMO - demonstration of testing a CICS program.
  • CONVERT - convert a CSV file into a fixed-format file.
  • FILEDEMO - demonstration of batch file mocks.
  • FIZZBUZZ - the classic FizzBuzz exercise.
  • INVDATE - calculate the date of the last day of the month.
  • PARADEMO - demonstration of mocking paragraphs.
  • SAMPLE - minimal unit test code for a "Hello, World!" program.
  • SUBPROG - demonstration of testing a called subprogram.

The unit test framework comprises:

  • ZUTZCPC - the precompiler that inserts test code into a copy of the program under test.
  • ZUTZCPD - PROCEDURE DIVISION copybook containing common test code.
  • ZUTZCWS - WORKING-STORAGE SECTION copybook containing common test code.

Why the funky names?

We want the unit test framework to be usable on zOS, *nix, and Windows systems. Most objects on zOS systems are limited to 8-character names, and IBM product names follow a certain pattern. We followed the same pattern in an informal way. Referring to this document, we did not find an existing product with the prefix ZUT. So, the names of the components in the unit testing framework mean:

  • ZUT - zOS Unit Test
  • ZC - zOS Cobol
  • PC - precompiler
  • PD - PROCEDURE DIVISION
  • WS - WORKING-STORAGE

More Repositories

1

online-learning-resources

Online resources for self-study in software-related topics and skills
61
star
2

t-rexx

Unit testing framework for Rexx
REXX
14
star
3

cobol-samples

COBOL
11
star
4

ide-katas

Katas for burning IDE keyboard shortcuts into your muscle memory
Java
10
star
5

bash-spec

Unit testing framework for bash scripts
Shell
5
star
6

java-legacy

Java
3
star
7

provision-cobol-dev-ubuntu

Provision an instance of Ubuntu Linux as a Cobol development environment using GNU Cobol
COBOL
2
star
8

directional-code-metrics

Directional code health metrics to monitor improvement
2
star
9

provision-lightweight-development-environments

General information about scripts to provision lightweight development environments on various platforms
2
star
10

api-mock

Lightweight API mocking framework for API testing
Java
2
star
11

java-use-types

Sample code to demonstrate how to create custom classes for domain concepts
Java
2
star
12

z390-assembly-unit-test

Toy project to explore automated unit testing of z390 assembly language code
COBOL
2
star
13

provision-java-dev-ubuntu

Provision an Ubuntu instance as a Java development environment
Shell
1
star
14

java-poker

Test bed for exploring different test automation techniques and refactoring steps
Java
1
star
15

java-dbc

Design by Contract library for Java
Java
1
star
16

self-start-ruby

Self-guided quick and dirty introduction to ruby.
1
star
17

tdd-java-231204-am

TDD Java course Dec 4-8 2023 morning
Java
1
star
18

tdd-231113-pm

HTML
1
star
19

tdd-java-ps

Code for TDD Java training
Java
1
star
20

java-legacy-starter

Starter code for a legacy remediation exercise in Java
Java
1
star
21

alu-simulator

Sandbox for learning about F# and Xunit
F#
1
star
22

copy-expander

Expand nested COBOL copybooks with the REPLACING option.
Ruby
1
star
23

help

General help with system problems
Ruby
1
star
24

dfhmdf

Convert DFHMDF macro source into text_field definitions compatible with the te3270 gem
Ruby
1
star
25

java-bookstore

Starter code for a technical training class
Java
1
star