Using Code Coverage with Visual COBOL



I need to show that I have tested all logical paths through a program.


Note: This facility is supported in native COBOL only.

Code Coverage

Visual COBOL provides support for code coverage of native COBOL applications directly from within the IDE. In order to produce reports, code coverage needs to be enabled within a project's properties, programs need to be compiled and run with code coverage to produce the relevant reports.

Follow these instructions to enable code coverage and produce code coverage reports:

  • Enable Code Coverage on the COBOL page in the properties of the project.

  • Rebuild the project to apply the changesThe application can now be run in code coverage mode by selecting Debug > Start With Micro Focus Code Coverage.

Running the application with code coverage will produce a Results.tcz file in the folder specified in Tools > Options > Micro Focus > Code Coverage > Results Options. This file provides statistics in the Micro Focus Code Coverage window and includes information about the percentage of the code that has been executed, as well using color to indicate areas of the code in the editor that have been executed or not executed. Code execution is logged for each program and sub-program. In addition HTML reports can be created from within the Micro Focus Code Coverage window. If the window is not visible, to display it click View > Micro Focus Code Coverage.


Double-clicking on a line within Code Coverage window will place the cursor on the relevant code within the Editor window.

The color preferences for the colorization of covered and missed blocks can be changed in Tools > Options > Environment > Fonts and Color:

The history of running the application with code coverage is saved in a History subfolder in the location of the Results.tcz file. The results from previous runs with code coverage can be loaded into the Micro Focus Code Coverage window (see below).

Micro Focus Code Coverage Window Toolbar

 Export code coverage information and save it as a .tcz results file.

 Import code coverage information from an existing .tcz results file.

 Merge results files from different executions with code coverage, this will create a MergedCoverageFile_datetime.tcz.

 Toggle the code coverage colorization on or off in the editor.

 Delete the Results_datetime.tcz that is currently loaded, this will unload the file from the IDE and deletes it from disk.

 Generate the code coverage HTML format reports. This creates the index report file, TCIndex.htm, and any of the reports in HTML format.


The IDE preferences determine whether to produce a single HTML report file or multiple reports (individual .HTM files produced for each program):

Single report file:

Click on of the tcreport.htm link to view the report.

Multiple report files:

Click on the links to view the individual reports.

Example report file:

The report includes a summary of the percentage of statements, Call statements, blocks etc. that have been executed in the program:

For further information, please refer to the product documentation.




Comment List