Code coverage (native COBOL)

Code coverage for native COBOL in Visual COBOL integrates the Micro Focus Test Coverage facility.
Note: This facility is supported in native COBOL only.

These are the steps to enable code coverage for your applications and then run them to produce code coverage reports:

  1. Enable code coverage in the properties of a project, a build configuration's or a file.
    Note: If different from the project settings, the build configuration settings take precedence over the project settings when you build your application. If you enabled code coverage at project level but do not receive any results when you run the application, it might be because the application was executed in a build configuration which does not have code coverage enabled. To work around this, always ensure code coverage is enabled for the build configuration you are running your application in.
  2. Compile your project to apply the changes.
  3. Create a launch configuration that has code coverage enabled and execute your application in it.

While an application is running with code coverage, code execution is logged for each program and sub-program that has been compiled with code coverage enabled. The results are stored in a binary results file which has the filename extension .tcz. In the IDE, you can specify your preferences for what level of details test coverage should write into the results file depends on how you configure test coverage.

For example, you can tag statements in your source code and use code coverage to report on whether these statements have been executed. This is particularly useful if you want to see the coverage of new or changed lines in your source code.

For convenience, Visual COBOL visualizes the code coverage information from the results file by showing statistics about covered (executed) or missed (unexecuted) blocks and programs in a Code Coverage view and by highlighting the covered and missed blocks in the editor in different colors. You can produce code coverage reports in HTML format.

Covered and missed blocks

A block is a section of code that, when executed, is executed consecutively and linearly. This means you can assume that if one part of the block executes, then the rest of the block has been executed as well.

Code that is not executed linearly (such as IF THEN ELSE statements, where the individual clauses in the statement are not executed in a single pass) includes more than one block of code.

Blocks of code that are executed are referred to as covered, while blocks of code that are not executed are referred to as missed.

Restrictions

Code coverage in the IDE utilizes the Test Coverage command line utility. The following restrictions of the Test Coverage utility also apply to code coverage:

  • Test coverage does not support nested programs. In particular, it does not work for programs which call the cobsetjmp() and coblongjmp() APIs that are used when calling nested programs.
  • Manually changing the execution point while debugging a program produces test coverage results that are unpredictable.
  • If you have a multi-threaded program (one that is compiled with the REENTRANT directive) and you compile it with the test coverage enabled and run it under test coverage, the test coverage results obtained will be unpredictable.
  • When you use test coverage with preprocessors, only the basic blocks of the original code are taken into account.

Micro Focus recommends that you do not use code coverage in a production system because of the increased requirements on system resources when running in code coverage mode. However, you can compile with code coverage enabled into your production system, if needed. Additionally, you should exercise caution when enabling code coverage on large remote projects, as this results in a significant amount of data transfer caused by the required project files being transferred locally for processing of the test coverage results.