Track code coverage in pipeline runs
This topic explains how to view data from your code coverage reports.
Code coverage overview
You can display code coverage data collected by JaCoCo (in XML format), or by other tools (LCOV format), or by fetching the coverage data collected by SonarQube using its REST API. This is only possible when SonarQube is integrated with Jenkins.
If you do not have a Jenkins or GitLab CI server, it is still possible to inject JACOCO-XML or LCOV coverage report formats, by using a dedicated REST API.
To enable frequent releases with minimal disruption and maximum quality, it is best to regularly run automated tests that cover as much of your code as possible. Code coverage on pipeline runs measures the percentage of lines in your code that were called during a particular run of the pipeline.
The information from all of the code coverage reports in your pipeline run is combined to show you a unified picture. Pipelines display widgets that show code coverage per package and per file, as well as code coverage trends over time. Using this information, you can track how much of your code is covered by automated tests.
Tracking code coverage involves the following steps:
-
Configure the code coverage reports, in one of the following formats:
- SonarQube
- Jenkins JaCoCo
- LCOV
- GitLab JaCoCo
-
Send the code coverage reports to OpenText Core Software Delivery Platform, using one of the following tools:
- Jenkins Application Automation Tools plugin
- REST API. For details, see Add coverage (technical preview).
-
View the code coverage information.
Get code coverage data from SonarQube
To view code coverage SonarQube data in OpenText Core SDP, you need to have a Jenkins job whose coverage is already displayed in SonarQube.
To get code coverage data from SonarQube:
-
Create the integration. For details. see SonarQube integration.
-
Set up the integration with your Jenkins server using the Application Automation Tools plugin. For details, see Set up CI/CD integration.
This feature requires version 5.7.2 or later of the plugin. This version is currently available as a beta version. If you are using an earlier version of the plugin, you can upgrade your plugin to this version.
-
Run the pipeline.
Get code coverage from Jenkins JaCoCo or LCOV
You can get code coverage data both from freestyle jobs and pipeline-as-code jobs.
Prerequisites: This integration requires standard industry tools such as Maven and JaCoCo generating code coverage JaCoCo or LCOV reports on your Jenkins server.
To get code coverage from Jenkins JaCoCo or LCOV:
-
Set up the integration with your Jenkins server using the Application Automation Tools plugin. For details, see Set up CI/CD integration.
This feature requires version 5.3.1 or later of the plugin. If you are using an earlier version of the plugin, you can upgrade your plugin to this version.
-
Freestyle jobs: For pipeline steps whose code coverage you want to track, create a post-build step that sends the code coverage reports. Select the ALM Octane code coverage publisher post-build step, and provide the paths to your code coverage reports.
-
Pipeline-as-code: Within your pipeline script, add the step publishCodeCoverage: ALM Octane code coverage publisher, and provide the path to your code coverage reports. (You can use the Snippet Generator to see sample syntax.)
Copy codeExample: Pipeline-as-code
stage('Publish Coverage') {
publishCodeCoverage jacocoPathPattern: ' **/site/jacoco-unit-test-coverage-report/jacoco.xml ', lcovPathPattern: '**/coverage-reports/lcov.info'
}
-
-
Run the pipeline.
Get JaCoCo code coverage data from GitLab
To get JaCoCo code coverage data from GitLab, set up the integration with GitLab as described in OpenText Core Software Delivery Platform GitLab CI service. The following section describes this procedure at a high level.
This feature requires version 1.1.126 or later of the service.
To get JaCoCo code coverage data from GitLab:
-
Configure the OpenText Core SDP GitLab CI service as described in the readme file.
To get code coverage data, define the following property, as described in the readme file:
gitlab.codeCoverage.variables.generatedCoverageReportFilePathVarName.
-
In your GitLab project, configure a variable for the property, as described in the readme file.
View code coverage data
All of the code coverage reports that belong to one pipeline run are received and aggregated. You can then see an overall picture of the code coverage in your pipeline runs and determine whether the coverage is improving over time.
To view code coverage data:
-
In the Pipelines > Analysis > Overview page, add the code coverage widgets to the pipeline dashboard.
-
Code coverage by pipeline run. Shows the overall percentage of code lines covered by automated tests in each pipeline run. Invest in developing automated tests for as much of your code as possible, aiming to develop and then maintain a high code coverage as your code base grows.
-
Code coverage by package. Shows the code coverage per package in your code base, as well as the percentage of code lines covered by automated tests in each file. For more details, see The 'Code coverage by package' widget.
Tip: Use the widget configuration's Scope settings to define which package to view as the root of the chart. For example, a team leader might want to focus on the package that is relevant to their team rather than viewing the full product hierarchy.
-
-
Click the pipeline's ID to open it.
In the Runs tab, you can see a code coverage bar on each pipeline run. Hover over the bar to see the exact number of files.
Represents the code lines that were not reached by any test runs.
Represents the code lines that were called at least once during the tests that ran as part of this pipeline run.
The 'Code coverage by package' widget
Use the Code coverage by package widget to quickly identify the largest areas in your code and the ones with the lowest code coverage. If important code packages are large and have low coverage, invest in creating more or better automated tests for those areas.
This widget is interactive and shows more information about the areas you hover over or click.
-
Each area in this sunburst chart represents a code package.
-
The size of each area indicates the amount of code lines in the package.
-
The color of the area represents the code coverage of this package. Red represents packages where no code lines were reached by any test runs. Green represents 100% code coverage. The colors and shades in between represent the range of code coverage percentage.
-
The circles represent the code package hierarchy, with the high-level packages closer to the center of the chart.
Hover over an area to see the package name and the code coverage percentage.
-
The outer rim of the chart represents code packages at the bottom of the hierarchy, which contain files. Click on areas in the outer rim to open a heatmap that shows coverage details per file.
-
Each area in the heatmap represents a file in the selected package.
-
The size of an area indicates the amount of code lines in the file.
-
The color of the area represents the level of code coverage.
-
Hover over an area to see the exact number of lines and code coverage percentage.
See also: