Go "FAIL package [build failed]" - Fix in CI
go test compiles each package plus its tests before running anything. If that compile fails, the package is reported as [build failed] and no tests execute.
What this error means
A run prints FAIL example.com/app/pkg [build failed] with a compile error above it. It means a _test.go file or the package itself does not build, not that an assertion failed.
go
# example.com/app/pkg [example.com/app/pkg.test]
./pkg_test.go:18:9: undefined: NewClient
FAIL example.com/app/pkg [build failed]Common causes
Compile error in a _test.go file
A test file references a symbol, signature, or import that no longer exists, so the test binary will not build.
The package under test does not compile
A non-test file in the same package has a compile error, which fails the whole test build.
How to fix it
Compile the tests directly
- Build the tests without running them to surface the compile error.
- Fix the undefined symbol or signature mismatch.
Terminal
go test -run=^$ ./... # compile tests, run none
go vet ./...Keep tests in sync with code
- Update _test.go files whenever you change a signature they call.
Terminal
go build ./... && go test ./...How to prevent it
- Run
go vet ./...so test files are compiled in CI lint. - Update tests alongside signature changes.
- Compile tests locally with
go test -run=^$ ./...before pushing.
Related guides
Go "build failed" loading test package imports - Fix in CIFix Go test "build failed" from a bad import in the test package in CI - a missing or wrong import path stops…
Go "go vet" failures block go test - Fix in CIFix Go test failures caused by the built-in go vet pass in CI - go test runs vet first and fails on its findi…
Go "go test: exit status 2" - Fix in CIFix Go "go test ... exit status 2" in CI - a build or tooling failure, not a test assertion, ended the run. R…