Use this process to create a unit test within a COBOL unit test project, for testing native COBOL or mainframe COBOL code.
This type of unit test calls into existing code in your workspace that you plan to test.
-
While in the COBOL perspective, select a COBOL unit test project in the COBOL Explorer pane.
-
Right-click the project, point to
New, and select
COBOL Unit Test.
The
New COBOL Unit Test dialog box appears.
-
Select
Program Unit Test, and then click
Next.
-
In the
Containing project field, ensure it states the name of your unit test project.
-
In the
New file name field, type the name of your test fixture program.
Restriction: Do not use the file name
mfunit, as this will not run within the
Micro Focus Unit Testing Framework.
-
To create a linked fixture file, select
Create unit test for program, then click
Browse, select the program that contains the code you want to test, then click
OK.
Note: The selected program must be from a local Native COBOL or mainframe project (for a local-based unit test project) or from
a project using the same remote connection (for a remote unit test project), and must be built to one of the following target
types: Single Native Library File, All Native Library Files, or All Int/Gnt Files - these can be used when the unit test project
links to a single or multiple projects. (The Single/All Executable Files target types are only supported for self-contained
unit tests.) Any linked project must also share the same
Platform Target setting as your test project.
-
Click
Next.
-
Configure only one of the following sections:
- Create unit test for entry points: select each entry point name within the source program that contains code you intend to test. Each selected entry point
has corresponding test entry points created in the generated fixture file.
- Create unit test for data source: for data-driven tests, select a data file (.csv file) with which to test source code from a particular entry point in your source program:
- Unit test data source - click
Browse, then select a .csv file that contains the data required for your unit tests. This value is used in the
MFU-MD-TESTDATA metadata when the tests are created.
- Data source delimiter - click
, (comma) and select the delimiter used in the file. This value is used in the
MFU-MD-DD-DSV metadata when the tests are created.
- Program entry point - select the entry point in the source program for which a test case is to be created. (Unlike the other type of unit test,
you can only select one entry point.)
-
Click
Finish.
The test fixture file is created within the unit test project.
The fixture file contains some auto-generated stub code based on the details specified. Some of the essential elements and
additional configuration (required for linked fixture files) are as follows:
- The two copybooks required by the
Micro Focus Unit Testing Framework are copied into the project.
- The test fixture elements (test setup, test case, etc...) have been created for each entry point selected.
- A procedure pointer has been added to the test setup that enables you to call into the source code, and a level 78 constant
for the test case name has been added (to help when creating the different elements of the test case).
- The Linkage section from the source program has been replicated in the Working-storage section, initialized, and a CALL statement
coded in the test case.
- The project containing the program under test is added to the
Projects tab of the
Build Path properties.
You can now start writing your test code; see
Writing Tests.