# Which test touched which service? Per-test coverage across microservices

> A coverage number per service tells you what the suite ran. It does not tell you what one test ran. Here is what a per-test footprint across microservices contains, where you read it, which parts are always exact, and what it is good for: failure diagnosis, test selection and finding the test that should exist.

Published 2026-11-18 · Updated 2026-11-18 · Melih Sakarya
Canonical: https://coverops.ai/blog/per-test-coverage-across-microservices

Short answer: per-test coverage across microservices means that for one test you can see the endpoints it called, every service each call crossed, the methods that ran in each of them, and the files and lines executed. CoverOps builds this by having the test name itself on its first request and having the agent in every service carry that name onward and file the work under it. The request, service and method part of that answer is always exact. The line part is exact unless several tests hit the same service process at the same moment, and in that case CoverOps tells you so instead of guessing.

## Why the number per service is not enough

A per-service report says how much of the orders service the integration suite ran. Useful for a team, but it cannot answer three everyday questions:

- A test failed. Which change broke it? You need the lines that test runs, in every service, to match against what changed.

- A pull request changed the inventory consumer. Which tests should run? You need to know which tests reach that consumer, even though none of them calls it directly.

- Nothing reaches the refund path. Which test is closest? You need to know what each existing test already does around it.

All three are questions about one test, not about the suite.

## How work is filed under a test

A test tells CoverOps three things on the traffic it sends: the test name (suite::name), an optional test id from your test management tool, and an optional run key. It can send them as headers, in W3C baggage, in a covctx cookie for browser tests, or in the query string. The runner integrations do this for you, and any HTTP client can do it by hand:

X-CoverageOps-Test: checkout%3A%3Arefunds%20a%20desk
X-CoverageOps-Test-Id: AUT-45
X-CoverageOps-Run: gh-9812

The agent in the first service reads these, keeps them with the request, and writes them on every outbound call and, where the agent supports it, on every message it publishes. The next service does the same. Each agent files the methods and lines it saw under that test, in that run.

One rule keeps this safe: traffic can only choose among runs that are already open in the project. Anyone who can reach a service can send a header, so a run named by traffic is honoured only while it is running, or for 10 minutes after it finished, for consumers that flush late. The test runner opens the run with its token before the first test.

## What one test's footprint contains

- The run and the test's verdict.

- The endpoints the test called and the services each call crossed, message consumers included where the context is carried.

- Every request in order, with its hops and the methods in each hop. A hop the agent did not sample says so (sampled: false) and shows no methods.

- The methods that ran, per service, and the files and lines executed.

Tests that start the application in their own process, such as a @SpringBootTest suite or pytest with --coverops-footprints, add an in-process footprint to whatever the services recorded from their traffic.

## Where you read it

- On the run page. Every test in the run is listed with its status and runner. Click one for its detail: the request Flow (each hop with service, duration and line count) and Coverage as "N lines in M files", each file opening the source with that test's lines marked.

- From a line. In the source view, a covered line offers "N tests touch this"; the file panel lists every test that ran the file and how many of its lines.

- From the runner's report. Every runner integration puts a link per test into its own report, of the form /runs/by-key/<run key>?test=<suite::name>. The person reading a red test opens what it did on the backend in one click.

- From code or an assistant. The footprint endpoint returns the same answer, and so does the MCP tool test_footprint.

curl -G "$COVERAGEOPS_ENDPOINT/v1/agent/runs/footprint" \
  -H "Authorization: Bearer $COVERAGEOPS_TOKEN" \
  --data-urlencode "run_key=gh-9812" --data-urlencode "test_id=AUT-45"

The response summarises requests, services, endpoints, methods, files and lines, lists each of them, and carries the path that opens the same test on the run page. Lookups are scoped to the token's project.

## What stays exact, and what can be shared

This is the part most tools leave vague, so here it is plainly.

- Always exact: the requests, endpoints, services and methods of a test. They come from per-request traces, and two tests' traces never mix.

- Exact unless tests overlap in one process: the lines. Line counters belong to the whole service process. When two tests' requests reach the same process at the same time, their lines cannot be told apart. CoverOps gives every test in that span all of the span's lines, so no test loses a line it ran, and records how many tests shared it. The test detail then says that it ran at the same time as N other tests against the same service, so its lines may include theirs; the API returns the count as coverage.shared_with.

- Exact by design: the .NET agent records lines per request through the request's async context, and PHP serves each request in its own process, so neither shares.

The parallel tests post in this series goes deeper into how each agent draws those windows and how to keep them small.

## What per-test coverage is good for

- Why a test is red. For each failed test, the run page compares it with its last green run and names the commits whose changed lines that test runs, in any service. A failure in the checkout test can point at a commit in pricing.

- Which tests a change needs. Impact and test selection read footprints, so a change in the inventory consumer selects the order test whose event reached it. Shared lines only ever select more tests, never fewer.

- Which test to write next. On an uncovered line, "what would cover this" points at the nearest scenario that reached the file. Below the test list, "Worth running here" lists flows from earlier runs that ran lines this run missed.

The live view helps while you set it up: during a run, steps stream in service by service, so you can see in the first minutes whether your tests' names are arriving in every service.

## Limits

- A hop that does not carry the context still has its coverage in the run, but not under the test. Check the service map for missing edges first.

- Lines are shared, not split, while tests overlap in one process. Requests, services and methods are not affected.

- A sampled-out hop appears without its methods.

- Databases, brokers and third-party services are not measured. Start-up code a service runs before any test reaches it belongs to no test.

- A test that sends no name has coverage in the run but no footprint of its own.

Start the series at functional test coverage in distributed systems, and make sure the hops are complete with the service map. On the change side, change impact analysis and test selection build on the same footprints. The run detail guide and the concepts guide have the details; the integration test coverage page has the summary.
