Setting code coverage acceptance levels

You can specify code coverage acceptance levels for one or more of the following elements: module, compilation unit, source file, or function. All criteria must be met in order for the program to be flagged as passing the code coverage requirements.

About this task

When you set code coverage levels, the level that you enter is the minimal acceptable percentage of code coverage. You can set acceptable code coverage levels for one or more of the following elements:
  • Module coverage
  • Compilation unit coverage
  • Source file coverage
  • Function coverage
By default, a code coverage result uses a module threshold of 80% as its only acceptance criterion.
Attention: Changing the threshold criteria for your code coverage results, results in the status column in the Compiled Code Coverage Results view being updated. For more information, see Working with the Compiled Code Coverage Results view.

Procedure

To customize the code coverage acceptance levels or thresholds:
  1. Select Window > Preferences.
  2. Select Run/Debug > Compiled Debug > Code Coverage.
  3. Specify the minimum acceptable percentage of code coverage for one or more of the following elements:
    • Module coverage: the percentage of lines that must be covered in the module in order to meet the acceptance criteria.
    • Compilation unit coverage: the percentage of lines that must be covered in the compilation unit in order to meet the acceptance criteria.
    • Source file coverage: the percentage of lines that must be covered in the source file in order to meet the acceptance criteria.
    • Function coverage: the percentage of lines that must be covered in a function in order to meet the acceptance criteria.
    Use the check boxes, to select the desired elements. Enter the minimum acceptable code coverage percentages in the associated box for each element selected.

  4. Click the OK button.
  5. To restore the default acceptance criteria for a code coverage result, open the code coverage preferences pages and click on the Restore Defaults button. The module threshold level will be reset to 80% and all other threshold levels will be deselected.

Note that all criteria must be met in order for the program to be flagged as passing the code coverage requirements. An icon will appear in the Compiled Code Coverage Results view indicating whether the acceptance criteria passed or failed. Additionally, each failed element is decorated in the report view with a red "x" overlay. For example, using the preference set above (source file acceptance level of 90%) yielded the following code coverage report for the payroll program. Note the red "x" overlay next to payroll.cpp because 89% code coverage is below the 90% acceptance criterion.


Feedback