What Should an API Test Coverage Tool Measure?
Endpoint coverage alone can read 100% on a suite that checks nothing. See the dimensions an API test coverage tool should measure, work one example by hand, then read the coverage panel in Shift-Left API.
This is lesson 5.9 of OpenAPI, Contract and Schema Testing, the last in the track. It uses ideas from lesson 5.3, where each schema rule became a test case; here you measure how many of those cases a suite really has.
What should an API test coverage tool measure?
An API test coverage tool should measure your tests against what the API documents, in several dimensions, not just one. "Every endpoint has a test" is the most common coverage claim and the least useful: one happy-path test per operation reads 100% endpoint coverage while leaving every error status, every parameter and every request rule untested. A useful tool counts status codes, parameters, body fields and assertions as well, each against the spec, and shows you the gaps by name.
The dimensions of REST API test coverage
| Dimension | Denominator (from the spec) | Numerator (from the tests) |
|---|---|---|
| Operations | Documented method and path pairs | Operations at least one test calls |
| Status codes | Documented responses per operation | Codes a test asserts |
| Parameters | Declared path, query and header parameters | Parameters a test sends |
| Request body fields | Fields in the request schema | Fields a test sends |
| Negative scenarios | Rules in the schema (required, limits, enums) | Rules a test breaks on purpose |
| Response checks | Response fields and their types | Fields a test asserts |
| Auth | Operations with a security scheme | Operations tested with no, bad and insufficient credentials |
Two principles make the numbers honest. First, a test only counts for a dimension when it asserts something: calling an endpoint and ignoring the answer covers nothing. Second, a dimension the spec doesn't describe is not applicable, not 100%: an operation with no request body has no body-field coverage to report.
OpenAPI test coverage, worked by hand
Take List products (GET /api/v1/products) from the sandbox spec. It documents one response, 200, and declares seven query parameters: page, limit, sort and order, plus three simulation parameters, delay, error and random_fail. It has no request body and no security scheme.
Now suppose the suite has one test: it calls List products with no parameters and asserts a 200.
| Dimension | Covered | Note |
|---|---|---|
| Operations | 1 of 1 | Called |
| Status codes | 1 of 1 | 200 asserted |
| Parameters | 0 of 7 | None sent |
| Request body | Not applicable | No body |
| Negative scenarios | 0 | limit of 101 or page of 0 never sent |
| Response checks | Minimal | Only the status |
| Auth | Not applicable | No security scheme |
By endpoint and status code, this endpoint is "fully covered". By parameters it is at zero, and nothing checks that limit above 100 is refused, even though the spec says it must be. That is why OpenAPI test coverage has to be multi-dimensional.
Notice the simulation parameters too. A coverage tool counts what the spec declares, so delay, error and random_fail count against you until a test sends them. Either test them or accept the gap knowingly; don't let it hide in an average.
How to measure API test coverage, step by step
- Take denominators from the spec, per operation: responses, parameters, body fields, security.
- Take numerators from the tests: what each one sends, and what it asserts.
- Exclude what doesn't apply instead of counting it as covered.
- Report per operation and per dimension, not one project-wide number. An average hides a critical endpoint at zero.
- List the gaps by name ("no test sends
limit", "no test asserts the 404"), so each one is a task. - Recompute on every spec change. A new parameter is a new gap the day it ships.
Coverage measured this way is spec coverage. It is different from code coverage, which counts lines of the server executed, and from traffic coverage, which compares tests with real production calls. Each answers a different question; spec coverage is the one a contract owner needs. For report contents and tool criteria, read API test coverage: how to measure it, dimensions and tools.
Common coverage traps
- Counting calls, not checks. A suite of
status is not 500tests reaches high coverage and catches little. - One project-wide percentage. It rewards many easy endpoints over a few hard ones.
- Ignoring negative scenarios. Happy paths alone can fill most dimensions in the table except the one that finds bugs.
- Counting stale tests. Tests for an endpoint version that no longer exists shouldn't count.
In Shift-Left API: the endpoint coverage panel
Shift-Left API measures coverage against the spec and against the scenarios its generator plans for each endpoint, not against production traffic or server code. Coverage on an endpoint is available in every edition; the project-wide coverage figure on Analytics → Project Analytics needs Professional, Enterprise or the trial. The API test coverage page has the full picture.
- With the sandbox spec imported, open Products, then List products, and click Generate tests.
- On the endpoint page, click Endpoint functional coverage to open the panel.
- Read the first line. Overall is functional coverage: scenarios, status codes, parameters and request body. Production-grade adds seven checks: schema validation, Content-Type, auth depth (401 and 403), method routing, a performance assertion, data integrity and error-body validation. Because coverage is measured against the scenarios the generator plans, one test can't make an endpoint read 100%.
- Read the counts: Scenarios, Status codes (out of 1), Parameters (out of 7) and Request body.
- Read the Coverage verdict: one line per dimension, with auth depth marked not applicable, because List products has no security scheme.
- Read the gap list. Each gap is one of 11 types, explained in plain language with the test that would close it.
- Click Generate tests for gaps. If a gap stays open because your project's own settings rule it out, such as performance switched off, it is flagged rather than silently skipped.
Tests marked stale after a regeneration never count as coverage.
Try it yourself
Import the sandbox spec, open Products, then List products, and click Generate tests. Open Endpoint functional coverage. What are the Overall and Production-grade scores? How many of the 7 parameters are covered, and which verdict line is marked not applicable?
Recap
- An API test coverage tool should measure against the spec, in several dimensions, and name each gap.
- REST API test coverage counts status codes, parameters, body fields and assertions, not just endpoints; a dimension the spec doesn't describe is not applicable.
- How to measure API test coverage honestly: denominators from the spec, numerators from what tests send and assert, reported per operation.
That completes the track. Next: Test Data, Mocks and End-to-End API Testing, starting with what a mock API is.
Try it: Import https://demo.totalshiftleft.ai/openapi/rest.json, open Products, then List products, click Generate tests, and open the Endpoint functional coverage panel.
Frequently asked questions
What is REST API test coverage?+
It is how much of a REST API's documented surface your tests exercise and check: which operations are called, which documented status codes are asserted, which parameters and body fields are sent, and which response fields are verified. It is measured against the API's definition, usually its OpenAPI spec, not against the server's source code.
How is OpenAPI test coverage calculated?+
For each operation, the spec gives the denominators: documented status codes, declared parameters and request body fields. Your tests give the numerators: the codes they assert, the parameters and fields they send. Each dimension is a fraction, and a tool combines them per operation and across the API. A dimension the spec doesn't describe should be left out, not counted as 100%.
How do you measure API test coverage beyond endpoints?+
Count status codes, parameters and body fields as well as operations, and check what the tests assert, not only what they call: a test with no assertion on the response covers nothing. Add negative and auth scenarios as their own dimensions, so a suite of happy paths can't look complete.
Related lessons
Every keyword in a schema is a rule, and every rule gives test cases. See the mapping keyword by keyword, what no generator can derive from a spec, and how to judge one, then generate tests in Shift-Left API.
A six-step method for API contract testing, from choosing where the contract lives to gating every release on it, with a contract suite built as a Test Run Pack in Shift-Left API.
Turn a pile of test runs into one screen your team can watch and share: a dashboard for each role, an export you can print to PDF, share links and a TV Mode wall display.