Go "go test ./...: build failed" - Fix Test Build Errors in CI
go test ./... could not compile a package or its test files, so the tests for it never ran. A build error in test code - a stale signature, a wrong import, a missing helper - fails the whole go test invocation.
What this error means
A go test ./... run reports FAIL <package> [build failed] (and an overall build failed) with the underlying compile error, instead of test results. The non-test build may even pass while the test build does not.
# github.com/org/app/internal/store [github.com/org/app/internal/store.test]
internal/store/store_test.go:18:21: undefined: newTestDB
FAIL github.com/org/app/internal/store [build failed]Common causes
Test files reference code that changed
A _test.go file calls a helper or API that was renamed, removed, or had its signature changed, so the test build fails even if the package builds.
A bad import or missing test helper
A wrong import path in a test file, or a test helper that was deleted, leaves the test binary unable to compile.
An external test package mismatch
A package foo_test file referencing unexported internals (or the wrong package) fails to build against the package under test.
How to fix it
Build the test binaries to surface the error
Compiling tests without running them isolates the build failure quickly.
go test -run xxx ./... # compiles tests, runs none
go vet ./... # also typechecks test filesFix the test code against the current API
- Read the compile error - it names the file, line, and missing/changed symbol.
- Update the test to the current helper/signature, or restore the missing helper.
- Re-run
go test ./...to confirm the build passes and tests run.
How to prevent it
- Run
go vet ./...so test files are typechecked alongside the build. - Update
_test.gocall sites when changing helpers or signatures. - Keep test imports and package declarations correct.