Go Test Failures in CI - Read FAIL Output and Exit Code 1
go test exits non-zero when a test reports a failure. Exit code 1 with --- FAIL lines is a genuine assertion failure - the code under test behaved differently than the test expected.
What this error means
go test ./... prints one or more --- FAIL: TestName blocks with the failing assertion and ends with FAIL and exit code 1. The failing test names and messages point straight at the problem.
--- FAIL: TestSum (0.00s)
sum_test.go:14: Sum(2, 3) = 6; want 5
FAIL
exit status 1
FAIL github.com/yourorg/app/math 0.012sCommon causes
A real behavior change or bug
The code under test returns something the assertion does not expect - a genuine regression or a test that needs updating to match intended new behavior.
Environment-dependent assertions
A test that depends on time zone, locale, ordering, or filesystem layout can fail in CI while passing locally because the environment differs.
How to fix it
Read the failing assertion and reproduce it
Run just the failing test verbosely to see the exact got/want.
go test -run TestSum -v ./math/...Fix the code or the expectation
- If the code is wrong, fix it so the assertion passes.
- If the test encodes an outdated expectation, update the expected value deliberately.
- For environment-dependent failures, make the test hermetic (inject the clock, fix the locale, sort before comparing).
How to prevent it
- Keep tests hermetic and independent of host time zone, locale, and ordering.
- Run
go test ./...locally before pushing. - Treat a
--- FAILas a real signal, not flake, until proven otherwise.