COBOL Tutorial

Progress0 of 0 lessons

COBOL program testing

Program testing is the process of checking that your COBOL program does what it should. It includes unit testing (testing one paragraph or program in isolation), running with test data, and debugging (breakpoints, step-through, inspecting data) when something goes wrong. This page introduces basic ideas and steps; for deeper debugging see Debugging.

Why test?

Testing finds bugs before the program is used in production. You run the program with known input and check that the output (or file updates, return codes) matches what you expect. If it doesn’t, you use a debugger or extra DISPLAY/logger output to find the cause. Regular testing after each change (regression testing) helps avoid breaking working behavior.

Basic testing steps

Typical testing flow
StepMeaning
Prepare test dataCreate input files and values that cover normal and error cases
Run in test environmentExecute the program (batch or online) with test data
Compare outputCheck actual output vs expected; use file compare or manual review
Use debugger if neededSet breakpoints, step through, inspect variables to find bugs

Test data

Prepare input that covers the cases you care about: normal records, empty files, invalid data, boundary values (e.g. zero, maximum length). Use small files or in-memory data so runs are fast and results are easy to check. You can use fixed test files in your test library or generate them with a small utility. Document what each test case is meant to prove.

cobol
1
2
3
4
5
*> Example: set test values before calling the paragraph under test MOVE "VALID-ID" TO WS-CUSTOMER-ID MOVE 100.50 TO WS-AMOUNT PERFORM VALIDATE-AND-PROCESS *> Then check WS-RESULT or output file contents

Unit testing a paragraph

To unit test one paragraph: (1) Set WORKING-STORAGE (and LINKAGE if it’s a called program) to known test values; (2) PERFORM the paragraph (or CALL the program); (3) Check that the result fields or side effects are correct. If the paragraph CALLs other programs, you can use stubs (dummy programs that return fixed values) so only the paragraph under test runs. That isolates failures to that unit.

Debugging: breakpoints and step-through

When a test fails, use a debugger if available. Set a breakpoint at the line or paragraph where you want to stop. Run the program; when it hits the breakpoint, execution pauses. Then step through statement by statement and inspect data items (counters, key fields, file status) to see where values go wrong. Compiling with a TEST or DEBUG option is often required for the debugger to work. See Debugging for more.

Step-by-step: run a simple test

  • Create a small test input file (or set WORKING-STORAGE in a driver paragraph).
  • Run the program in a test environment (batch job or development region).
  • Capture the output (report, output file, return code).
  • Compare to expected results; if they differ, use the debugger or DISPLAY to find the bug.
  • Fix the bug and re-run the same test (regression) plus any new tests.

Test Your Knowledge

1. What is unit testing?

  • Testing the whole system end-to-end
  • Testing one module or paragraph in isolation with controlled input
  • Testing only the DATA DIVISION
  • Testing on the production system

2. Why use a breakpoint when debugging COBOL?

  • To compile faster
  • To stop execution at a chosen point and inspect data
  • To skip the PROCEDURE DIVISION
  • To run the program twice

Related concepts

Related Pages