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:
Add the
coveragekeyword 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+)?\%)$/'To aggregate coverage from multiple jobs, add the
coveragekeyword 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.
| Tool | Language | Command | Regex pattern |
|---|---|---|---|
| pytest-cov | Python | pytest --cov | /TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/ |
| Simplecov-html | Ruby | rspec spec | /Line\sCoverage:\s\d+\.\d+%/ |
| Tool | Language | Command | Regex pattern |
|---|---|---|---|
| gcovr | C/C++ | gcovr | /^TOTAL.*\s+(\d+\%)$/ |
| tarpaulin | Rust | cargo tarpaulin | /^\d+.\d+% coverage/ |
| Tool | Language | Command | Regex pattern |
|---|---|---|---|
| JaCoCo | Java/Kotlin | ./gradlew test jacocoTestReport | /Total.*?([0-9]{1,3})%/ |
| Scoverage | Scala | sbt coverage test coverageReport | /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/ |
| Tool | Command | Regex pattern |
|---|---|---|
| tap | tap --coverage-report=text-summary | /^Statements\s*:\s*([^%]+)/ |
| nyc | nyc npm test | /All files[^|]*|[^|]*\s+([\d\.]+)/ |
| jest | jest --ci --coverage | /All files[^|]*|[^|]*\s+([\d\.]+)/ |
| node:test | node --experimental-test-coverage --test | /all files[^|]*|[^|]*\s+([\d\.]+)/ |
| Tool | Command | Regex pattern |
|---|---|---|
| pest | pest --coverage --colors=never | /Statement coverage[A-Za-z\.*]\s*:\s*([^%]+)/ |
| phpunit | phpunit --coverage-text --colors=never | /^\s*Lines:\s*\d+.\d+\%/ |
| Tool | Command | Regex 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+%/ |
| Tool | Language | Command | Regex pattern |
|---|---|---|---|
| OpenCover | .NET | None | /(Visited Points).*\((.*)\)/ |
| dotnet test | .NET | dotnet test | /Total\s*|*\s(\d+(?:\.\d+)?)/ |
| Pester | PowerShell | None | /Covered (\d{1,3}(\.|,)?\d{0,2}%)/ |
| Tool | Command | Regex pattern |
|---|---|---|
| excoveralls | None | /\[TOTAL\]\s+(\d+\.\d+)%/ |
| mix | mix 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:
- In the top bar, select Search or go to and find your project.
- In the left sidebar, select Settings > Merge requests.
- Under Merge request approvals, do one of the following:
- Next to the
Coverage-Checkapproval rule, select Enable. - For manual setup, select Add approval rule, then enter
Coverage-Checkas the Rule name.
- Next to the
- Select a Target branch.
- Set the number of Required number of approvals.
- Select the Users or Groups to provide approval.
- 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
- In the top bar, select Search or go to and find your project.
- In the left sidebar, select Analyze > Repository analytics.
- From the dropdown list, select the job you want to view historical data for.
- Optional. To download the data, select Download raw data (.csv).
For a group
- Tier: Premium, Ultimate
- In the top bar, select Search or go to and find your group.
- In the left sidebar, select Analyze > Repository analytics.
- 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.