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.
# 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.
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.
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.