Coverage reporting

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

Use the coverage keyword to extract a coverage percentage from your test job’s log output and display it in merge requests and analytics.

This keyword displays a coverage percentage only. It does not produce line-by-line annotations in the MR diff. To display line annotations, configure artifacts:reports:coverage_report separately.

Configure coverage reporting

To configure coverage reporting:

  1. Add the coverage keyword to your job with a regular expression that matches your test tool’s output:

    test:
      script:
        - pytest --cov
      coverage: '/TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
  2. To aggregate coverage from multiple jobs, add the coverage keyword to each job.

Coverage regex patterns

The following regex patterns match output from common test coverage tools. Test these carefully, as tool output formats can change over time.

ToolLanguageCommandRegex pattern
pytest-covPythonpytest --cov/TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
Simplecov-htmlRubyrspec spec/Line\sCoverage:\s\d+\.\d+%/
ToolLanguageCommandRegex pattern
gcovrC/C++gcovr/^TOTAL.*\s+(\d+\%)$/
tarpaulinRustcargo tarpaulin/^\d+.\d+% coverage/
ToolLanguageCommandRegex pattern
JaCoCoJava/Kotlin./gradlew test jacocoTestReport/Total.*?([0-9]{1,3})%/
ScoverageScalasbt coverage test coverageReport/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
ToolCommandRegex pattern
taptap --coverage-report=text-summary/^Statements\s*:\s*([^%]+)/
nycnyc npm test/All files[^|]*|[^|]*\s+([\d\.]+)/
jestjest --ci --coverage/All files[^|]*|[^|]*\s+([\d\.]+)/
node:testnode --experimental-test-coverage --test/all files[^|]*|[^|]*\s+([\d\.]+)/
ToolCommandRegex pattern
pestpest --coverage --colors=never/Statement coverage[A-Za-z\.*]\s*:\s*([^%]+)/
phpunitphpunit --coverage-text --colors=never/^\s*Lines:\s*\d+.\d+\%/
ToolCommandRegex pattern
go test (single)go test -cover/coverage: \d+.\d+% of statements/
go test (project)go test -coverprofile=cover.profile && go tool cover -func cover.profile/total:\s+\(statements\)\s+\d+.\d+%/
ToolLanguageCommandRegex pattern
OpenCover.NETNone/(Visited Points).*\((.*)\)/
dotnet test.NETdotnet test/Total\s*|*\s(\d+(?:\.\d+)?)/
PesterPowerShellNone/Covered (\d{1,3}(\.|,)?\d{0,2}%)/
ToolCommandRegex pattern
excoverallsNone/\[TOTAL\]\s+(\d+\.\d+)%/
mixmix test --cover/\d+.\d+\%\s+|\s+Total/

Add a coverage check approval rule

  • Tier: Premium, Ultimate

You can require specific users or a group to approve merge requests that reduce the project’s test coverage.

Prerequisites:

  • Configure coverage reporting.

To add a Coverage-Check approval rule:

  1. In the top bar, select Search or go to and find your project.
  2. In the left sidebar, select Settings > Merge requests.
  3. Under Merge request approvals, do one of the following:
    • Next to the Coverage-Check approval rule, select Enable.
    • For manual setup, select Add approval rule, then enter Coverage-Check as the Rule name.
  4. Select a Target branch.
  5. Set the number of Required number of approvals.
  6. Select the Users or Groups to provide approval.
  7. Select Save changes.

The Coverage-Check approval rule requires approval when the merge base pipeline contains no coverage data, even if the merge request improves overall coverage.

View coverage history

You can track coverage trends for your project or group over time.

For a project

  1. In the top bar, select Search or go to and find your project.
  2. In the left sidebar, select Analyze > Repository analytics.
  3. From the dropdown list, select the job you want to view historical data for.
  4. Optional. To download the data, select Download raw data (.csv).

For a group

  • Tier: Premium, Ultimate
  1. In the top bar, select Search or go to and find your group.
  2. In the left sidebar, select Analyze > Repository analytics.
  3. Optional. To download the data, select Download historic test coverage data (.csv).

Display coverage badges

To add a coverage badge to your project, see test coverage report badges.

Troubleshooting

When working with coverage reporting, you might encounter the following issues.

Coverage percentage does not appear in the MR widget

The coverage keyword extracts a percentage from your job’s log output using a regular expression. If the percentage does not appear:

  • Verify your regex matches your tool’s actual output. Copy a line from the job log and test it against your regex.

  • Some tools output ANSI color codes that break regex matching. If your tool does not support disabling color output, strip the codes before parsing:

    lein cloverage | perl -pe 's/\e\[?.*?[\@-~]//g'
  • Check that the job completed successfully. Coverage is only extracted from successful jobs.

  • Coverage output from child pipelines is not recorded. For details, see issue 280818.

The coverage keyword only shows a percentage in the MR widget. For line-by-line annotations in the diff, configure artifacts:reports:coverage_report separately.