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.
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.
| Step | Meaning |
|---|---|
| Prepare test data | Create input files and values that cover normal and error cases |
| Run in test environment | Execute the program (batch or online) with test data |
| Compare output | Check actual output vs expected; use file compare or manual review |
| Use debugger if needed | Set breakpoints, step through, inspect variables to find bugs |
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.
12345*> 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
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.
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.
1. What is unit testing?
2. Why use a breakpoint when debugging COBOL?