- View Code Coverage results
- Coverage check approval rule
Use code coverage to provide insights on what source code is being validated by a test suite. Code coverage is one of many test metrics that can determine software performance and quality.
View Code Coverage results
Code Coverage results are shown in:
- Merge request widget
- Project repository analytics
- Group repository analytics
- Repository badge
For more information on test coverage visualization in the file diff of the MR, see Test Coverage Visualization.
View code coverage results in the MR
If you use test coverage in your code, you can use a regular expression to find coverage results in the job log. You can then include these results in the merge request in GitLab.
If the pipeline succeeds, the coverage is shown in the merge request widget and in the jobs table. If multiple jobs in the pipeline have coverage reports, they are averaged.
Add test coverage results using
To add test coverage results to a merge request using the project’s
.gitlab-ci.yml file, provide a regular expression
Test coverage examples
Use this regex for commonly used test tools.
- Simplecov (Ruby). Example:
- pytest-cov (Python). Example:
- Scoverage (Scala). Example:
pest --coverage --colors=never(PHP). Example:
phpunit --coverage-text --colors=never(PHP). Example:
- gcovr (C/C++). Example:
tap --coverage-report=text-summary(NodeJS). Example:
nyc npm test(NodeJS). Example:
jest --ci --coverage(NodeJS). Example:
- excoveralls (Elixir). Example:
mix test --cover(Elixir). Example:
- JaCoCo (Java/Kotlin). Example:
go test -cover(Go). Example:
/coverage: \d+.\d+% of statements/.
- .NET (OpenCover). Example:
- .NET (
dotnet testline coverage). Example:
- tarpaulin (Rust). Example:
- Pester (PowerShell). Example:
View history of project code coverage
Introduced the ability to download a
.csvin GitLab 12.10.
- Graph introduced in GitLab 13.1.
To see the evolution of your project code coverage over time, you can view a graph or download a CSV file with this data.
- On the top bar, select Main menu > Projects and find your project.
- On the left sidebar, select Analytics > Repository.
The historic data for each job is listed in the dropdown list above the graph.
To view a CSV file of the data, select Download raw data (
View history of group code coverage
To see the all the project’s code coverage under a group over time, you can find view group repository analytics.
You can use pipeline badges to indicate the pipeline status and test coverage of your projects. These badges are determined by the latest successful pipeline.
Coverage check approval rule
- Introduced in GitLab 14.0.
- Made configurable in Project Settings in GitLab 14.1.
When merging a request that would cause the project’s test coverage to decline, you can stipulate that such merge requests require approval by selected users or a group.
Follow these steps to enable the
Coverage-Check MR approval rule:
- Set up a
coverageregular expression for all jobs you want to include in the overall coverage value.
- Go to your project and select Settings > Merge requests.
- Under Merge request approvals, select Enable next to the
- Select the Target branch.
- Set the number of Approvals required to greater than zero.
- Select the users or groups to provide approval.
- Select Add approval rule.
Remove color codes from code coverage
Some test coverage tools output with ANSI color codes that aren’t parsed correctly by the regular expression. This causes coverage parsing to fail.
Some coverage tools do not provide an option to disable color codes in the output. If so, pipe the output of the coverage tool through a one-line script that strips the color codes.
lein cloverage | perl -pe 's/\e\[?.*?[\@-~]//g'