Skip to content

Coverage for integration tests #4372

Open
@hanwen-flow

Description

@hanwen-flow

See https://go.dev/blog/integration-test-coverage

I'm trying to get coverage for this scenario, but for an end-to-end test (in Go, let's say e2e_test) that calls a Go binary as a subprocess (let's call it runner) compiled with Bazel.

I've tried bazelisk coverage $MYTESTTARGET. While the target itself generates data for a coverage report, the subprocess doesn't.

I see -cover_mode set in the compilation flags, and the link command-line has -extldflags '--coverage ... .

If I manually call coverage.WriteCounters from runner, I get

dumpCoverage("/home/hanwen/.cache/bazel/_bazel_hanwen/9456475fcdc74345a14b5217fb53a469/s.../e2e_test/_coverage"): WriteCounters invoked for program built with -covermode=<invalid> (please use -covermode=atomic)

calling WriteMeta from runner yields:

2025/06/05 16:22:29.500353 dumpCoverage("/home/hanwen/.cache/bazel/_bazel_hanwen/9456475fcdc74345a14b5217fb53a469/.../e2e_test/_coverage"): error: no meta-data available (binary not built with -cover?)

I'm using Go 1.24.3 with Bazel 9.0.0-pre.20250516.1, and rules_go 0.54.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions