The following example creates a simple test case that includes setup code, a simple test that writes to a data file, and a teardown that tidies up the test at the end. You can enhance this test further by including your own test assertions in the main test case section.
A new test program is created, and within it, the stub-code for your first test case.
environment division. input-output section. file-control. select cust assign to 'cust.txt' organization is line sequential.
And add the following immediately after the line data division:
file section. fd cust. 01 cust-file. 03 customer-id pic 9(5). 03 customer-info pic x(65).
open output cust
This sets up the test, by opening the file, ready for any file operations performed in the test case itself.
move 0 to customer-id perform 100 times add 1 to customer-id move "A customer" to customer-info write cust-file end-perform
The test case performs a simple write operation on the file. if this fails, the test case is marked as failed. This is also the section in which you would add your own test assertions; see Determining a Test Outcome for more information.
move "This is a simple test to write to a data file" to MFU-MD-TESTCASE-DESCRIPTION
close cust
The teardown section tidies up the environment.