Skip to content
Latchkey

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

  1. Build the tests without running them to surface the compile error.
  2. Fix the undefined symbol or signature mismatch.
Terminal
go test -run=^$ ./...   # compile tests, run none
go vet ./...

Keep tests in sync with code

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →