ZUnit (z/OS Automated Unit Testing Framework)

ZUnit is an adaptation of the xUnit framework for writing code to run repeatable, self-checking unit tests. The ideas and framework that are developed in xUnit for unit testing object-oriented code are adapted by ZUnit for testing Enterprise COBOL and PL/I code.

Restriction: z/OS® Automated Unit Testing Framework (ZUnit) is not supported on macOS.
The following image illustrates the ZUnit components and how they interact. Each component is described in the table.
ZUnit implements the following components for unit testing Enterprise COBOL and PL/I code:
Component Description
Test runner The test runner is a z/OS batch application that runs one or more test cases that are defined in an input configuration and generates a consolidated report of the results after all test cases are run. The format of the test runner configuration and test runner results report is UTF-8 XML. The test runner can be configured to stop running tests or test cases if assertions or unexpected errors are detected. In the case where the test runner is configured to stop running tests or test cases when assertions or unexpected errors are detected, the results report contains only information about the tests and test cases that ran.
Test case Test cases are Enterprise COBOL or PL/I programs that are structured according to the expectations of the test runner. Each test case contains at least one test that is a subprogram (COBOL) or procedure (PL/I). Tests are expected to be independent of one another, and to that end, the test fixture that is required to run a test is established, used, and discarded before the next test is run. To ensure that test cases are also independent of one another, the test runner unloads a test case from memory before it runs the next test case.
Assertions Assertions verify that the actual behavior of code under test matches the expected behavior. For example, if within a test T, a program P does not return expected output E given input I, the test fails with an assertion because P(I) != E.
Test fixture A test fixture is a test context or environment that a test case writer establishes in the setup() entry before each test entry in a test case. All the resources that are allocated in the setup() entry are normally discarded in the teardown() entry after each test is completed.
Test execution Tests are run by the test runner when it is started with an input configuration that indicates which test cases to run and defines processing options.
Test runner API The ZUnit test runner API exposes a set of APIs for use by Enterprise COBOL or Enterprise PL/I test cases. The following APIs are provided:
  • AZUTCINI: Initialize and register a COBOL or PL/I ZUnit test case with the ZUnit test runner.
  • AZUTCADD: Add a subprogram (COBOL) or procedure (PL/I) as a test to be run by the test runner.
  • AZUASTFM: Fail a test in an Enterprise COBOL or Enterprise PL/I test case with a user-supplied message that indicates the reason for the failure.
  • AZUASTFA: Fail a test in a COBOL or PL/I test case without a user-supplied message.