Go Coverage "no statements" - Fix Empty Coverage Results in CI
By Kaveh Alemi·Latchkey
A coverage run produced an empty or misleading result. A -coverpkg pattern that matches no tested package, or a package with no executable statements, makes Go warn and report 0.0% or [no statements] - which can silently pass a coverage gate.
What this error means
A go test -cover run prints warning: no packages being tested depend on matches for pattern ..., or a package reports coverage: [no statements] / 0.0% of statements. The suite "passes" but covers nothing meaningful.
go test output
warning: no packages being tested depend on matches for pattern github.com/org/app/internal/...
ok github.com/org/app/cmd 0.012s coverage: [no statements]
Diagnose it: environment first
Terminal
go version
go env GOOS GOARCH CGO_ENABLED GOFLAGS GOPRIVATE GOPROXY
go mod verify
Common causes
A -coverpkg pattern that matches nothing tested
The packages named by -coverpkg are not imported by any package under test, so Go has nothing to instrument and warns.
A package with no executable statements
A package that is only declarations (constants, types, interfaces) reports [no statements] because there is nothing to cover.
How to fix it
Align -coverpkg with the tested packages
Point coverage at packages the tests actually import, or measure per-package coverage instead.
Terminal
go test -coverpkg=./... -coverprofile=cover.out ./...
go tool cover -func=cover.out
Treat the warning as a gate signal
Decide whether the warned packages should be tested; if so, add tests that import them.
Exclude declaration-only packages from coverage thresholds rather than counting them.
Fail CI on the warning if empty coverage indicates a misconfigured gate.
How to prevent it
Keep -coverpkg patterns in sync with what your tests import.
Exclude declaration-only packages from coverage targets.
Inspect go tool cover -func output, not just the pass/fail.
Frequently asked questions
What causes Go coverage "no statements"?
There are 2 common causes: a -coverpkg pattern that matches nothing tested and a package with no executable statements. The packages named by -coverpkg are not imported by any package under test, so Go has nothing to instrument and warns.
How do I fix Go coverage "no statements"?
There are 2 fixes depending on which cause you have: align -coverpkg with the tested packages and treat the warning as a gate signal. Work through them in order, since the first is the most common.
What does Go coverage "no statements" actually mean?
A go test -cover run prints warning: no packages being tested depend on matches for pattern ..., or a package reports coverage: [no statements] / 0.0% of statements.
How do I stop Go coverage "no statements" happening again?
Keep -coverpkg patterns in sync with what your tests import. The prevention section lists 3 changes that keep it from recurring.