Go Coverage "no statements" - Fix Empty Coverage Results in CI
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.
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]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.
go test -coverpkg=./... -coverprofile=cover.out ./...
go tool cover -func=cover.outTreat 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
-coverpkgpatterns in sync with what your tests import. - Exclude declaration-only packages from coverage targets.
- Inspect
go tool cover -funcoutput, not just the pass/fail.