Skip to main content
Skip to content

Code coverage reference

Code Quality shows what percentage of the lines of your code your tests actually exercise, so you can find untested code before you merge.

Code coverage measures what percentage of the lines in your source code are executed when your test suite runs. Code Quality displays line coverage on pull requests after you set up code coverage. The repository coverage overview also shows current line coverage for the default branch and how it changes over time.

Note

Code Quality reports line coverage only. Coverage tools often also report function, branch, or statement coverage. Code Quality does not currently use these metrics, even if your Cobertura XML report includes them, and they are not shown on pull requests or evaluated by coverage threshold rules.

How line coverage is calculated

The line coverage percentage represents the number of lines covered by tests divided by the total number of executable lines, expressed as a percentage.

Line coverage on pull requests

On pull requests, Code Quality stores the latest upload for each branch (including the default branch) and compares the pull request branch line coverage to the default branch line coverage. For example, if your default branch has 44% line coverage and your pull request branch has 65% line coverage, the pull request gained 21 percentage points of line coverage.

Per-file delta

The per-file breakdown on pull requests shows how line coverage changed for each modified file. A positive delta means the file gained line coverage on the pull request branch compared to the default branch.

Total line coverage in the repository coverage overview

Note

The repository coverage overview is in public preview and subject to change.

The repository coverage overview shows total line coverage for your default branch and how it has changed over time.

How total line coverage is calculated

You can upload more than one coverage report for a repository. For example, you might upload separate reports for unit tests and integration tests. The repository coverage overview combines these reports to calculate total line coverage:

  • Each line is counted once in the total, even if it appears in multiple reports.
  • A line is covered if any report shows that at least one test ran it.
  • A line is identified by its file path, as written in the report, and its line number.

Example

Suppose your repository contains JavaScript and Go code. The JavaScript code has unit tests, and the Go code has both unit tests and integration tests. You upload one report for each test suite.

Report (language / label)Executable linesCovered lines
javascript / unit200120
go / unit300180
go / integration300150

Both Go reports describe the same 300 lines of code. Of the 150 lines covered by integration tests, 90 are also covered by unit tests. Together, the Go reports cover 240 distinct lines.

CodeExecutable linesCovered lines
JavaScript200120
Go300240
Total500360

The total line coverage is 360 / 500, or 72%.

Coverage for a single report

To see coverage for a single report, filter the overview by both its language and its label. For example, filtering by language:go and label:integration shows 150 / 300, or 50%.

Further reading