Skip to content
Latchkey

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.

go test output
# 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.

Terminal
go test -run xxx ./...      # compiles tests, runs none
go vet ./...                # also typechecks test files

Fix the test code against the current API

  1. Read the compile error - it names the file, line, and missing/changed symbol.
  2. Update the test to the current helper/signature, or restore the missing helper.
  3. 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.go call sites when changing helpers or signatures.
  • Keep test imports and package declarations correct.

Frequently asked questions

What causes ""go test ... build failed""?
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.
How do I fix "go test ... build failed"?
Compiling tests without running them isolates the build failure quickly.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card