> ## Documentation Index
> Fetch the complete documentation index at: https://hitspec.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# API Coverage

> Measure how much of your API is covered by tests using OpenAPI spec comparison and coverage reports.

API coverage tracking compares your test files against an OpenAPI specification
to show which endpoints have tests and which do not. This helps identify gaps in
your test suite.

## Usage

Enable coverage with the `--coverage` flag and point to your OpenAPI spec:

```bash theme={null}
hitspec run tests/ --coverage --openapi api-spec.yaml
```

The `--openapi` flag is required when `--coverage` is set. Coverage runs after
your tests complete and the report is printed to the console.

## What Coverage Tracks

The coverage report shows:

* **Overall coverage percentage** -- the ratio of tested endpoints to total endpoints in the spec
* **Covered endpoints** -- endpoints that have at least one test request matching the method and path
* **Uncovered endpoints** -- endpoints defined in the spec with no matching test
* **Coverage by tag/category** -- grouped by OpenAPI tags if present

## Flags

| Flag         | Description                                                   |
| ------------ | ------------------------------------------------------------- |
| `--coverage` | Enable API coverage tracking (requires `--openapi`)           |
| `--openapi`  | Path to the OpenAPI/Swagger specification file (YAML or JSON) |

## Example

Given an OpenAPI spec with 20 endpoints and tests covering 15 of them:

```bash theme={null}
$ hitspec run tests/ --coverage --openapi spec.yaml

Tests: 15 passed, 0 failed
Coverage: 15/20 endpoints (75%)

Uncovered:
  GET  /api/admin/settings
  PUT  /api/admin/settings
  POST /api/reports/generate
  GET  /api/reports/{id}/download
  DELETE /api/users/{id}/sessions
```

## CI/CD Integration

Use coverage reporting in your CI pipeline to track coverage over time:

```yaml theme={null}
- name: Run API tests with coverage
  run: |
    hitspec run tests/ \
      --coverage \
      --openapi api-spec.yaml \
      --output junit \
      --output-file results.xml
```

<Tip>
  Run coverage checks locally before pushing to catch missing tests early. Pair
  coverage with the [OpenAPI import command](/reference/import-export) to
  generate test stubs for uncovered endpoints.
</Tip>
