-
Notifications
You must be signed in to change notification settings - Fork 28
Test Suite Syntax
Home -> User Guide ->
This document was last updated on February 11, 2021.
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 DSL is free-form. We recommend using blank lines and indentation consistently so that test suites will be easy to read. The DSL is case-agnostic, so you can also use any conventions you please for capitalization.
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 descriptive names for test suites and test cases without worrying about over-running column 72 (but Cobol Check does not support infinitely long text).
A caveat as of February, 2021: The pre-processor is not smart enough to break up long literals into more than two lines. We are planning to improve this at some point, but it is not a high priority at present. If you need more text than that to describe a test suite or test case, we recommend you use comments.
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!"
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.
Specify Cobol statements to be executed once after running all test cases.
After All
Cobol statement 1
Cobol statement 2
. . .
Cobol statement n
End-After
Specify Cobol statements to be executed after running each test case.
After Each
Cobol statement 1
Cobol statement 2
. . .
Cobol statement n
End-After
Specify Cobol statements to be executed once before running any test cases.
Before All
Cobol statement 1
Cobol statement 2
. . .
Cobol statement n
End-Before
Specify Cobol statements to be executed before running each test case.
Before Each
Cobol statement 1
Cobol statement 2
. . .
Cobol statement n
End-Before
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"
COMP-3-ITEM-1 [not] to be value (or COMP-3-ITEM-2 or COMP-ITEM-2 or DISPLAY-NUMERIC-ITEM-2)
COMP-ITEM-1 [not] to be value (or COMP-3-ITEM-2 or COMP-ITEM-2 or DISPLAY-NUMERIC-ITEM-2)
DISPLAY-NUMERIC-ITEM-1 [not] to be value (or COMP-3-ITEM-2 or COMP-ITEM-2 or DISPLAY-NUMERIC-ITEM-2)
[not] to equal
[not] =
[not] !=
[not] >
[not] >=
[not] <
[not] <=
88-LEVEL-ITEM-1 [not] to be true
[not] to be false
Cobol Check adheres to the definition that a unit test does not touch external dependencies of the code under test. It only exercises the logic of the code under test. Therefore, all external dependencies are stubbed by default. There is no "Stub" keyword.
If you want a stubbed resource to exhibit behavior when the code under test accesses it, you can use the Mock keyword to define such behavior.
Mock resource-identifier
on action
Cobol statements specifying the behavior of the mocked resource for the specified action
on action
Another action for the same mocked resource
End-Mock
Specifies a test data provider for a parameterized test case.
PROVIDER StateNames
HEADER 'Abbreviation', Name'
ROW 'AZ', 'Arizona'
ROW 'KY', 'Kentucky'
ROW 'XX', '*Undefined*'
Mandatory start of a test case. The description is echoed to the output of each test run.
TestCase "This is a single test case"
TestCase using provider-name "This is a parameterized test case" <- [0.4.0]
Optional description of a set of unit test cases. The description is echoed to the output of each test run.
TestSuite "This is a set of tests for my wonderful program"
Verify is used with Mock to check the number of times the mocked resource was accessed by the code under test during the test case.
verify mock-identifier happened
never happened
happened once
happened n times