Skip to content

One coverage view for services in Java, .NET, Node.js, Python, Go and PHP

By Melih Sakarya · Published · 5 min read

Bu yazının Türkçesi →

CoverOps Agents screen: a live fleet grouped by service, with each replica's last report and up/idle state

Short answer

Every language has its own coverage tool and its own report format, so a system built in six languages ends up with six numbers nobody can add up. Here is how CoverOps measures services in Java, .NET, Node.js, Python, Go and PHP into one run, follows one test across all of them, and where the languages still differ.

Short answer: a system whose services are written in Java, .NET, Node.js, Python, Go and PHP can be measured as one, if every service runs an agent that speaks the same protocol. CoverOps has an agent for each of these six runtimes. They read the same run key, the same test context and the same chain header, so every service of a build lands in one run, one test can be followed from a Java gateway through a Go service to a PHP module, and the run page shows each service's coverage side by side, merged into one system figure.

Six coverage tools do not add up

Each ecosystem has a good coverage tool: JaCoCo, coverage.py, V8 and Istanbul, Go's -cover, coverlet, pcov. Each writes its own format, at its own moment, for its own process. Put six of them in a test environment and you get six reports for the whole suite, written on shutdown, copied out of six containers, in at least three formats. Merging them gives a number, but not the two things a functional suite needs: which test reached which code, and whether the services a test crossed were measured at all.

What makes a polyglot system measurable as one is not a common file format. It is a common contract between the agents inside the services.

The contract every CoverOps agent follows

  • One run key. COVERAGEOPS_RUN_KEY, else the CI build id (the first of GITHUB_RUN_ID, BUILD_NUMBER, CI_PIPELINE_ID, BUILD_BUILDID, CIRCLE_WORKFLOW_ID), else local-YYYYMMDD. Same order in every agent, every test runner integration and the CLI.
  • One test context. The test's name, id and run, read from X-CoverageOps-* headers, W3C baggage, the covctx cookie or the query string, in that order.
  • One chain header. X-CoverageOps-Trace carries the trace and the hop between services, so a request that crosses four services in four languages arrives as one trace with four hops.
  • One set of settings. COVERAGEOPS_ENDPOINT, COVERAGEOPS_TOKEN, COVERAGEOPS_TRACE, COVERAGEOPS_ENVIRONMENT, COVERAGEOPS_INSTANCE mean the same thing everywhere.
  • One failure behaviour. Uploads run on the agent's own thread, never the application's. When CoverOps is unreachable or busy, agents retry within fixed bounds and never hold a service on the way down.

How each runtime attaches

  • Java: -javaagent on the JVM, through JAVA_TOOL_OPTIONS in a container. No code changes; line, branch and method coverage.
  • Node.js: node --require @coverageops/node-agent/register, or the same in NODE_OPTIONS. Coverage comes from V8's own precise coverage; lines, branches and functions.
  • .NET: a post-build step weaves probes into your assemblies, and DOTNET_STARTUP_HOOKS loads the agent, with a hosting startup for ASP.NET Core attribution. .NET Framework 4.7.2+ is supported too; there the woven code starts the agent itself.
  • Python: python -m coverageops_agent in front of your app or server (uvicorn, gunicorn), on top of coverage.py. Per-test lines and call chains need one line: WsgiMiddleware or AsgiMiddleware around the app.
  • Go: Go has no runtime attach, so it is two lines, not zero: build with -cover -covermode=atomic, import the agent and wrap the handler in coverageops.Middleware.
  • PHP: auto_prepend_file in php.ini or the FPM pool, with pcov (or Xdebug) as the coverage driver. One file, no Composer package.

A test environment then looks like this, with endpoint and token set the same way on every service:

services:
  gateway:          # Java
    environment:
      JAVA_TOOL_OPTIONS: "-javaagent:/opt/coverageops/agent.jar"
      COVERAGEOPS_TRACE: "true"
      COVERAGEOPS_RUN_KEY: ${CI_PIPELINE_ID}
  pricing:          # Go, built with -cover -covermode=atomic
    environment:
      COVERAGEOPS_TRACE: "true"
      COVERAGEOPS_RUN_KEY: ${CI_PIPELINE_ID}
  notifications:    # Node.js
    command: node --require @coverageops/node-agent/register server.js
    environment:
      COVERAGEOPS_TRACE: "true"
      COVERAGEOPS_RUN_KEY: ${CI_PIPELINE_ID}

CoverOps Agents screen: a live fleet grouped by service, with each replica's last report and up/idle state

Carrying one test across languages

Every agent reads the test context on the way in. Passing it on to the next service is where the runtimes differ:

  • Java forwards it by itself on the JDK's HTTP clients, Apache HttpClient 4 and 5 and OkHttp (so RestTemplate and Feign), and on Kafka and RabbitMQ messages.
  • Node.js forwards it by itself on http, https and fetch.
  • Go needs one line on the client.
  • Python, .NET and PHP put the agent's outbound headers on the call.
// Go
client := &http.Client{Transport: coverageops.Transport(nil)}

# Python
headers.update(current_tracer().outbound_headers())

// .NET
foreach (var h in CoverageOps.Agent.TestContext.Current.OutboundHeaders())
    request.Headers.TryAddWithoutValidation(h.Key, h.Value);

// PHP
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($headers, coverageops_outbound_headers()));

Once the context crosses, the run page shows the test's flow hop by hop, whatever each hop was written in, with the methods and lines it ran.

One test's call chain in CoverOps: each request hop in order, the service it reached, and the lines it ran, followed by the files the test covered

Test runners in any language, against services in any language

The test suite does not have to be written in the language of the services it tests. A pytest suite can drive Java services; a Playwright suite can reach a .NET backend through the browser. Each runner integration does the same four things: reads the same configuration, opens the run once, labels each test's traffic and reports the verdicts.

  • Java: JUnit 5 and TestNG, shipped in the agent jar.
  • JavaScript and TypeScript: Playwright, Cypress, WebdriverIO, Jest, Vitest, Mocha.
  • Python: pytest and Robot Framework.
  • .NET: a dotnet test logger for NUnit, xUnit and MSTest.
  • Go: coverageops-gotest in place of go test.

Postman, k6 or curl can send the three headers themselves.

Where the languages still differ

  • Branches. Java and Node.js report branch coverage; .NET, Python, Go and PHP report lines and methods.
  • Parallel tests. The .NET agent records lines per request through the request's async context, and PHP serves each request in its own process, so per-test lines stay exact there. Java, Node.js, Python and Go share a window between tests that overlap on one process; every overlapping test keeps all of its lines and the overlap is recorded.
  • Effort to attach. Java, Node.js and PHP attach without code. .NET adds a build step. Go and Python's per-test middleware need a line in the application.
  • Code graph. The source index behind the Code tab parses Java, TypeScript and JavaScript. Code in other languages appears on the traced side and on the Structure map.

The Agents screen also offers a Ruby agent, and C and C++ coverage comes from the compiler through the CLI; both report into the same runs.

Limits to know

  • A service without an agent is not measured, whatever its language.
  • A hop that does not carry the test context still has its coverage in the run, but not under the test.
  • Message hops outside the JVM are carried by hand.
  • Only code that runs in a process with an agent counts: not databases, brokers or third-party services.

This post is part of the functional test coverage in distributed systems series. Next: following a test through Kafka and per-test coverage across microservices. The agents guide has setup for every runtime, the integrations guide covers the test runners, and the integration test coverage page has the product summary.

Related posts

  • Parallel functional tests and per-test coverage: what stays exact, what is shared

    Functional suites run in parallel to fit into CI, and every parallel test hits the same long-running services. Line counters cannot say which of two simultaneous requests ran a line. Here is what CoverOps keeps exact anyway, what it shares and labels, how each agent draws the line, and how to keep the shared part small.

  • Paralel fonksiyonel testlerde test bazında coverage: ne kesin kalır, ne paylaşılır

    Fonksiyonel suite'ler CI süresine sığmak için paralel koşar ve her paralel test aynı uzun ömürlü servislere gider. Satır sayaçları, aynı anda gelen iki istekten hangisinin bir satırı çalıştırdığını söyleyemez. CoverOps'un yine de neyi kesin tuttuğunu, neyi paylaştırıp işaretlediğini, her agent'ın sınırı nasıl çizdiğini ve paylaşılan kısmı nasıl küçük tutacağınızı anlatıyoruz.

  • Changed-code coverage as a merge gate when a change spans services

    Diff coverage from one repository's unit tests cannot see that the new lines in the inventory consumer only run when an end-to-end test places an order. Here is how to gate a merge on the changed lines your functional tests actually ran, in every service, and how to keep a service that did not run from quietly passing the gate.

See which tests reach your own code

We connect one of your services in a demo and show what your tests executed, and what they never reached.