# Set a code coverage threshold with the Bun test runner (/docs/guides/test/coverage-threshold)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 357 · updated: 2026-07-28 -->
Related: [Run your tests with the Bun test runner](/docs/guides/test/run-tests.md), [Run tests in watch mode with Bun](/docs/guides/test/watch-mode.md), [Migrate from Jest to Bun's test runner](/docs/guides/test/migrate-from-jest.md), [Mock functions in `bun test`](/docs/guides/test/mock-functions.md), [Spy on methods in `bun test`](/docs/guides/test/spy-on.md), [Set the system time in Bun's test runner](/docs/guides/test/mock-clock.md)

Bun's test runner has built-in code coverage reporting. Enable it with the `--coverage` flag.

```sh terminal icon="terminal"
bun test --coverage
```

```txt
test.test.ts:
✓ math > add [0.71ms]
✓ math > multiply [0.03ms]
✓ random [0.13ms]
-------------|---------|---------|-------------------
File         | % Funcs | % Lines | Uncovered Line #s
-------------|---------|---------|-------------------
All files    |   66.67 |   77.78 |
 math.ts     |   50.00 |   66.67 |
 random.ts   |   50.00 |   66.67 |
-------------|---------|---------|-------------------

 3 pass
 0 fail
 3 expect() calls
```

***

To set a minimum coverage threshold, add the following to your `bunfig.toml`. A threshold of `0.9` requires that tests cover 90% of your codebase.

```toml bunfig.toml icon="settings"
[test]
# to require 90% line-level and function-level coverage
coverageThreshold = 0.9
```

***

If your test suite does not meet this threshold, `bun test` exits with a non-zero exit code to signal a failure.

```sh terminal icon="terminal"
bun test --coverage
```

```txt
<test output>
$ echo $?
1 # this is the exit code of the previous command
```

***

You can set different thresholds for line-level and function-level coverage.

```toml bunfig.toml icon="settings"
[test]
# to set different thresholds for lines and functions
coverageThreshold = { lines = 0.5, functions = 0.7 }
```

***

See [Code coverage](/test/code-coverage).
