Overview
C/C++test CT can generate code coverage reports in various formats. Reports are generated based on coverage data files produced with the cpptestcov compute
command, which is an obligatory step in the report generation process. See the example below:
cpptestcov compute -map=.cpptest/cpptestcc -clog=cpptest_results.clog -out=cov-data
Once coverage data files are available, reports can be generated with the following command:
cpptestcov report <report format> <options> <coverage data files directory>
For example:
cpptestcov report text -coverage LC cov-data
Report generation process does not modify the coverage date files. You can generate multiple reports from the same coverage data files.
C/C++test CT supports the following reporting formats:
Format | Description |
---|---|
cobertura | Cobertura format, may be useful for integrations with external tools |
dtp | Publish coverage and test results to DTP. Published reports are visible in the Parasoft DTP |
html | Coverage report in HTML format; see also Coverage Report with Code Annotations. |
json | Coverage statistics in json format |
lcov | Line Coverage report in lcov format, useful for integrations with external tools |
markdown | Coverage statistics in Markdown format |
mcdc | Text report with MCDC tables |
suppressed-lines | Text report with suppressed lines coverage information |
suppressions | Text report with suppressed coverage elements |
text | Coverage statistics in plain text format |
uncovered-lines | Text report with uncovered lines |
See Command Line Reference for cpptestcov for more details regarding reporting options syntax.
Coverage Report with Code Annotations
Generating HTML Reports
C/C++test CT provides advanced HTML reporting with source code annotations for complete insight into the coverage results. To generate an HTML report with code annotations, use the cpptestcov report html
command with the -code
option. To include multiple coverage metrics, use the -coverage
option and specify the desired set of metrics.
Example:
The HTML report will include source code annotations for the Line Coverage, Decision Coverage and MCDC metrics. It will be generated based on the coverage data files from the cov-data folder, and the main report file will be report/coverage.html:
cpptestcov report html -code -coverage LC,DC,MCDC -out report/coverage.html cov-data
Run cpptestcov report html --help
to view a complete list of options.
Report Structure
The generated HTML report has a nested (drill-down) structure with the following levels:
- project (with per-folder statistics) - the main report file, specified with the
-out
option - folder (with per-file statistics)
- file (with per-function statistics and annotated source code)
- Use the navigation buttons to move between levels.
- Click on the table header to sort the coverage statistics table.
By default, the full (absolute) path to tested source file will be presented on the report. To remove the host-specific part of the path, use the -root
option and specify the root location of the project, when generating the report.
Example:
The source file project/main.cpp will be displayed instead of the full path /home/user/dev/project/main.cpp:
-root /home/user/dev/project
Code Annotations
HTML coverage reports should be generated with the -code
option.
To access source code annotations, drill down to the file-level report. This report includes the source code for the selected file, with additional coverage-related annotations for each coverable line of the source code:
- Coverage status indicators for all enabled metrics
- Coverage highlights for selected metrics
- Coverage details for selected metrics
- Expandable coverage details for Decision Coverage, Simple Condition Coverage and MCDC metrics
Each type of coverage annotations can improve understanding of the coverage results. They can be used individually or combined, depending on the use case and preference.
Coverage Status Indicator
The coverage status indicator allows you to quickly find code locations with missing (or incomplete) coverage. It is a cumulative indicator for all coverage metrics included in the report, regardless of the currently selected metrics.
The following color code is used:
- Green - all coverage elements related to the given line are fully covered
- Yellow - some coverage elements related to the given line are partially covered
- Red - some coverage elements related to the given line are not covered
Coverage Highlights for Selected Metrics
The coverage highlights shows coverage elements directly in the source code. Only currently selected coverage metrics are visualized (see "coverage selectors").
The following color code is used:
- Green - coverage element is fully covered
- Yellow - coverage element is partially covered
- Red - coverage element is not covered
When multiple coverage metrics are selected, the code highlights may overlap. The not-covered (red) or partially-covered (yellow) highlights will always overlap the fully covered elements (green).
Coverage Details for Selected Metrics
The left bar shows coverage details for the currently selected metrics, with each metric displayed in its own column. It uses the same color code as the coverage highlights:
- Green - coverage element is fully covered
- Yellow - coverage element is partially covered
- Red - coverage element is not covered
In addition to the color code, the left bar uses symbolic indicators ([+][-]
) to visualize details about coverage elements, making it easier understand possible gaps in the code coverage results.
Coverage metric | Coverage details indicators |
---|---|
Line Coverage |
|
Statement Coverage |
|
Block Coverage |
|
Decision Coverage |
Each branch of a decision has its own indicator, for example: |
MCDC |
Each condition of a decision has its own indicator, for example: |
Simple Condition Coverage |
Each condition is presented as a |
Function Coverage |
|
Call Coverage |
|
If there are multiple coverage elements of given type in the same line (e.g. multiple statements), each element will be presented separately, for example:
Coverage metric | Multiple coverage details indicators in the same line |
---|---|
Statement Coverage |
|
Simple Condition Coverage |
|
Expandable Coverage Details for Simple Condition, Decision and MCDC Metrics
Additional coverage details for the elements of Simple Condition Coverage, Decision Coverage and MCDC type are available as expandable in-line comments. You can either view the details for an individual line or expand (or collapse) all lines with details at once.
This section is especially useful when working with the MCDC metric. The expandable coverage details provide insight into which condition values were tested, as well as which condition values are missing to achieve 100% of MCDC for a given decision. It also provides information which pairs of input vectors were considered when computing the MCDC values for each condition of a decision.