# Coverage in Tern

Press `c` on the Tests page and the run comes back with a **Coverage** tab: totals, the measured files and, for the
file you select, every line tinted by whether the tests ran it. In the source editor the same measurement tints the
rows under your caret while you keep editing.

## Run with coverage

| From | How |
| --- | --- |
| A Tern terminal | `elide test --coverage` |
| The Tests page | **Run with coverage** (`c`) |
| The source editor | **Run with coverage** (`F5`) in the **Coverage** overlay |
| Tern's agent | `test_cover(binding, subject, command)`; see [Shared sessions](/docs/tern-workspace#shared-sessions-with-terns-agent) |

**Run again** keeps the run's coverage option. Each run keeps its own measurement, so earlier runs in the history are
unchanged.

## Coverage tab

The tab appears once the run is measured. It shows the line and branch totals, files measured and uncovered lines,
then the measured files with their covered, partly covered and uncovered lines. Selecting a file shows its current
source with each measured line tinted; a file over 600 lines shows without highlighting.

| Key | Action |
| --- | --- |
| `j` `k`, `↑` `↓` | Select a file. |
| `n`, `p` | **Next uncovered** and **Previous uncovered** line. |
| Click **Open line N in Elide source** | Open the file at that line in the source editor. |

Lines the runtime does not measure, such as closing braces, blank lines and comments, take a lighter tint when the
block they belong to ran. They are not counted in the percentages. Branch counts show where the runtime reports them;
a file without branch data says so instead of showing zero.

Buttons that open files, such as **Open in Elide source** and **Open** on a test's card, respond to a click, not
`Enter`. ⌘-click a linked file name to open it.

## Source editor

The **Coverage** overlay of the [source editor](/docs/tern-workspace#source-editor) tints rows from the project's newest
coverage run while you keep editing:

| Tint | Line |
| --- | --- |
| Success | Covered. |
| Lighter success | Not measured, inside a block that ran. |
| Warning | Partly covered; the branch count shows beside the line. |
| Error | Uncovered. |
| Muted | Edited since the measurement. |

The toolbar badge and status bar show the file's percentage. When the file on disk no longer matches the measured
source, every tint turns muted and the editor says `Coverage measured an older version`. `F6` refreshes from the newest
run.

## Measured source

A measurement describes the source the runtime evaluated, even when the file changed before the report was written.
A missing source fingerprint or branch measurement means the data is unavailable; it does not mean the file is current
or that no branch ran. Line coverage records whether a line ran, not how many times. A report holds up to 2,000 files
and 200,000 lines.

Report formats and the coverage artifact: [Coverage](/docs/toolchain/testing#coverage).

## Next

Tests measured, the next thing to fix is the build. [Build diagnostics](/docs/tern-build) puts each javac and kotlinc
error on its line.
