Skip to content

Test Suite Syntax

Dave Nicolette edited this page Feb 4, 2021 · 17 revisions

Home -> User Guide -> General User Guide ->

Cobol-check uses a domain specific language (DSL) for specifying unit tests. The DSL is intended to resemble Cobol source code, so it will be intuitive for Cobol programmers to use, but it is not actually Cobol and will not compile. The test suites have to be pre-processed to produce a Cobol source file that contains all the test cases.

Modern Cobol source on most platforms is free-form, but the traditional source line format is still relevant on z/OS systems as the rest of the environment still has the original System 360 design elements at heart.

The cobol-check DSL is mostly free-form, except that you place an asterisk in column 7 to denote a comment line. Test suites will be most readable if you adhere to the Area A / Area B convention, but there are no "rules" about whether to place a keyword such as TESTCASE in Area A or Area B. In general, we find it helpful to write TESTSUITE and TESTCASE in Area A and the other DSL statements in Area B, and to leave a blank line between test cases.

When the pre-processor interprets test suite input files, it reads them character-by-character rather than line-by-line. That means you have a degree of freedom for source format. In particular, it means you needn't worry about writing continuation lines for long alphanumeric literals. The pre-processor will insert those lines into the test program source in the appropriate way. You can code long, descriptive names for test suites and test cases without worrying about over-running column 72.

Capitalization

Cobol-check is case-agnostic.

Most of the sample code is written in uppercase letters. This is not required. These are equivalent:

           TestCase "When message type is greeting it returns 'Hello, World!'"
           SET MESSAGE-IS-GREETING TO TRUE
           PERFORM 2000-SPEAK
           Expect WS-GREETING To Be "Hello, World     !"

           testCASE "When message type is farewell it returns See you later, alligator!"
           SET MESSAGE-IS-FAREWELL TO TRUE
           PERFORM 2000-SPEAK
           expect WS-FAREWELL to be "See you later, alligator!"

Structure

           TestSuite _"description"_ 

           TestCase _"description"_ 
               _Cobol statements to set preconditions for the test case_ 
               PERFORM _paragraph to be tested_ 
               Expect _data-item-name_ to be _expected-value_ 

           TestCase _"another one"_ 
               _Cobol statements to set preconditions for the test case_ 
               PERFORM _paragraph to be tested_ 
               Expect _data-item-name_ to be _expected-value_ 

See below for more syntax details.

Keywords (alphabetical)

Expect

This is the assertion statement. It is the last statement in a test case and declares the expected result of the test case. The general format is:

           Expect actual-result conditional-keyword(s) expected-result

Currently-supported conditional formats are:

   Expect ALPHA-ITEM-1       [not] to be    "value" (or 'value' or ALPHA-ITEM-2)
          ALPHA-ITEM-1(4:3)  [not] to equal "value"
                             [not] =        "value"
                             [not] !=       "value" 
                             [not] >        "value" 
                             [not] >=       "value" 
                             [not] <        "value" 
                             [not] <=       "value" 
       

TestCase "description"

Mandatory start of a test case. The description is echoed to the output of each test run.

           TestCase "This is a single test case" 

TestSuite "description"

Optional description of a set of unit test cases. The description is echoed to the output of each test run.

Example:

           TestSuite "This is a set of tests for my wonderful program" 

Clone this wiki locally