Introduction: Code Coverage
Working out which parts of a program have been executed and run can be a daunting task. Manually trying to work out the control flow is time consuming and error prone. In Micro Focus Visual COBOL and Enterprise Developer we have support for recording code coverage of native COBOL applications, making this task significantly easier. Code coverage is a measure of how much of an application is executed, usually as part of a test suite.
This is great for identifying areas of code that may not be executed during a run of the application. And better still for deciding which areas are in need of further testing. Micro Focus supports this functionality in both Eclipse and Visual Studio (VS) IDEs, but I will be showing VS as it is my IDE of choice.
Enable Code Coverage
To get started, the developer first needs to enable the code coverage support in the project that results are to be gathered from. This will build the application with the coverage instrumentation enabled, allowing execution data to be recorded. Note that there is a small performance overhead, so it is not recommended to enable this on production systems.
– Open project Properties
– Under the COBOL tab, check the Enable code coverage checkbox
– Rebuild the application
Run with Code Coverage
Once the application has been built with Code Coverage enabled, the application needs to be run. Behind the scenes, the IDE will set up a .tcf configuration file for the run which is required by the COBOL runtime to record coverage data.
– Click the Debug menu
– Click Start With Micro Focus Code Coverage
If there are MFUNIT test projects present, it is possible to gather the coverage data for a test run. To do so:
– Open the Micro Focus Unit Testing tool window
– Click the Run All (Code Coverage) button.
When the application has finished running, a .tcz file will be generated. This contains all the recorded data and is opened automatically by the IDE after the run. The data will be shown in the Micro Focus Code Coverage Tool Window. This includes the number of statements executed and percentage coverage. When coverage data is loaded, highlighting will be shown in open editor windows (this behaviour can be toggled).
The Micro Focus Code Coverage Tool Window provides two types of view on the data depending on the needs of the developer.
– Program View – Displays coverage in the context of individual programs.
– File View – Shows data for a file irrespective of what program may have copied it. Useful for analysing coverage in copybooks that contains program statements that may be copied by many different programs.
From the Command Line
It is also possible to record coverage data without the use of the IDE. A developer may want to gather the data from a CI run. For instructions on how to do this, please see the Micro Focus documentation and make sure you follow Micro Focus AMC on Twitter…….