Code coverage

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

Use coverage reporting and coverage visualization to track code coverage. The two mechanisms read different inputs, produce different outputs, and don’t share configuration. Configuring one does not enable the other.

Coverage reporting shows a percentage in the MR widget, the pipeline list, and analytics graphs. Coverage visualization shows line-by-line annotations in the MR diff. To get both, configure both keywords (coverage and artifacts:reports:coverage_report).

Where coverage appears

Use this table to find the keyword for the coverage output you want. The coverage keyword powers every output except diff annotations.

SurfaceWhere to find itKeywordTier
Coverage percentage and delta against the target branchMR widgetcoverageFree
Line-by-line annotationsMR diff, changed files onlyartifacts:reports:coverage_reportFree
Per-job coverage percentagePipeline and job listscoverageFree
Coverage badgeAnywhere you embed the badge URLcoverageFree
Coverage history and CSV exportAnalyze > Repository analytics (project)coverageFree
Group coverage history and CSV exportAnalyze > Repository analytics (group)coveragePremium and Ultimate
Coverage-Check approval ruleSettings > Merge requestscoveragePremium and Ultimate

Choose an approach

The two mechanisms read different inputs and behave differently.

Coverage reportingCoverage visualization
Keywordcoverageartifacts:reports:coverage_report
InputA regular expression matched against the job logA Cobertura or JaCoCo XML artifact
ProducesA single number per jobPer-line annotations on changed files
AvailableWhen the job completesAfter the whole pipeline completes
Child pipelinesNot recordedRecorded
Fails byShowing no percentageSilently skipping annotations

Because the two mechanisms read different inputs, they can disagree. The percentage in the MR widget is whatever your regex matched in the log. The annotations come from the XML report. If your test command computes these on different bases, the widget and the diff describe different things. Generate both from the same test run.

Coverage reporting

Coverage reporting extracts a percentage from your test tool’s job log output. You define a regular expression in the coverage keyword. GitLab scans the job log, extracts the first matching number, and stores it.

GitLab displays this value in:

  • The MR widget, including the delta compared to the target branch.
  • The pipeline job list.
  • Per-project and per-group coverage history graphs in Analyze > Repository analytics.
  • Coverage badges.
  • The Coverage-Check approval rule (Premium and Ultimate), which can require approval when coverage drops.

For setup instructions, see configure coverage reporting.

Coverage visualization

Coverage visualization parses a Cobertura or JaCoCo XML report that your test job uploads as a CI/CD artifact. After the pipeline completes, GitLab processes the report in the background and annotates lines in the MR diff.

Annotations appear only on files that are changed in the MR diff. Files not changed in the MR are not annotated, even if the report includes coverage data for them.

For setup instructions, see configure coverage visualization.