Viewing the Code Coverage Information

Note: This facility is supported in native COBOL only.

Running an application with code coverage produces a .tcz report file. Visual COBOL uses the information in this file to provide statistics in the Code Coverage view about what percentage of the code has been executed as well as to colorize the code in the editor to indicate covered (executed) and missed (not executed) blocks as well as covered and unexecuted programs.

From the Code Coverage view, you can navigate to the covered and missed blocks of code in the editor, import code coverage data from existing .tcz files or merge the report files produced from different runs of the application, and relaunch the application in code coverage mode.

Code coverage statistics

After executing an application with code coverage, the IDE automatically opens the Code Coverage view to display the code coverage information. (If the view is not visible, to display it click Window > Show View (or Show View > Other), expand Micro Focus, click Code Coverage, then click OK).

The view visualizes the code coverage information from the filename.tcz results file produced during the latest run with code coverage. The view shows the sections and the paragraphs in a program and what percentage of the code has been executed (covered) or not (not covered):

GUID-5165DF12-18F1-4135-AA7E-9F1F060A38A7-low.png

Covered and missed blocks

To view the covered and missed blocks, either scroll down the code of a COBOL program or double-click the lines of the program's structure in the Code Coverage view:

Covered and missed blocks

You can specify your color preferences for the colorization of covered and missed blocks as follows:

  1. In the IDE, click Window > Preferences > General > Editors > Text Editors > Annotations.
  2. Specify your preferences for the Covered Block and Missed Block items in the Annotation types list.

Editing the code after producing coverage results

The information displayed in the Code Coverage view and the colorization of the editor reflect the state of the application at the time it was executed to produce that specific coverage results file. If you then make a change in the code and compile it, this might move the code in the editor. As a result, the colorization in the editor might not accurately match the information displayed in the Code Coverage view. The data displayed in the Code Coverage View will still reflect the historical state of the program when the data was generated.

Other situations where the colorization in the editor might not accurately represent the information in the code coverage view include:

  • The results from running with code coverage are accumulated in a single results file (Accumulate data successive runs is enabled on the Dynamic Analysis tab in the application's launch configuration).
  • When loading a merged results file that includes the data from different runs with code coverage.
  • When loading a results file from running the application with code coverage before you changed the code.

Importing existing code coverage results

To import the code coverage information from an existing .tcz results file:

  1. In the Code Coverage view, click Import Session (Import Session).
  2. Use the Connection list to specify whether the file is on your local disk or on a remote machine.
  3. Navigate to and select an existing code coverage report .tcz file, then click OK.

    This imports the code coverage statistics from the .tcz file into the Code Coverage view and adds colorization to your source files indicating the missed and the covered blocks.

Note: If, after producing the code coverage data for an application, you then change a program and compile it, this does not automatically update the code coverage information displayed in the IDE. The code coverage file that was generated before the change still provides the older data and colorization of lines might not be able to do anything that's correct - it won't be able to understand the change and adjust for it. Note that, though the colorization in the editor might be incorrect, the data shown in the code coverage view is still correct.

Situations in which this behavior might occur are:

  1. You have checked the Accumulate data successive runs checkbox on the Dynamic Analysis tab in the launch configuration which you use for running the application.
  2. If you have merged multiple results files available in the code coverage history and the program has changed the different runs with code coverage that produced code coverage data.
  3. If you have selected to load and display the results from running the application with code coverage before you changed your program.

Rerunning the application with code coverage

After making changes to your application, to rerun the application with code coverage results:

  1. In the Code Coverage view, click Relaunch (Relaunch).

    This starts the application.

  2. Run and then exit the application to produce new code coverage results.

Deleting code coverage results

To delete the coverage results currently displayed in the Code Coverage view:

  1. In the Code Coverage view, click GUID-D9BB73C5-2266-4C5E-8647-A65F4555666A-low.png (Remove Current Coverage Results).

To delete all code coverage results:

  1. In the Code Coverage view, click GUID-26EB8D50-0BB9-414C-8C75-4E568D483C38-low.png (Remove All Coverage Results).

Merging the code coverage results from different runs

You can merge the results file from different executions with code coverage. This provides combined statistics of running the application in different scenarios. To merge the results:

  1. In the Code Coverage view, click Merge History Items (Merge History Items).
  2. In the Code Coverage Merge History Items dialog box, check the results files you want to merge, specify a name for the new results file, then click OK.

    This creates a new results file that includes the combined statistics and opens it in the Code Coverage view.

Viewing previous code coverage results

Visual COBOL preserves the history of the previous results of running the application with code coverage.

Click Manage History (Manage History) to view and load the statistics from previous runs with code coverage, to remove previous results, or to configure how many items are preserved in the history.

Showing unexecuted programs

The Code Coverage view displays information about any programs that were not executed. Click Manage History (Show Unexecuted Program Information) to toggle showing the unexecuted programs on and off.