Skip to content
Latchkey

Go Test Cache "(cached)" - Fix Stale or Skipped Test Runs in CI

Go caches successful test results and prints (cached) instead of re-running a package whose inputs are unchanged. This is usually a feature, but it can confuse CI when a test depends on something Go does not track as an input.

What this error means

go test ./... reports ok <pkg> (cached) and finishes almost instantly, so a test you expected to re-run did not. A change to an external input (an env var, a fixture file outside the package) is not reflected because the cache key did not change.

go test output
ok  	github.com/yourorg/app/api	(cached)
ok  	github.com/yourorg/app/store	(cached)
# tests did not actually execute this run

Common causes

Inputs Go does not track changed

The test cache keys on source, dependencies, and a known set of inputs. A test that reads an untracked env var, network service, or external file can be cached even though that input changed.

Expecting a fresh run every time

CI sometimes needs tests to run unconditionally (e.g. flaky-detection or environment-sensitive suites), but caching skips re-execution of unchanged packages.

How to fix it

Force a fresh run

Disable the cache for runs that must execute every time.

Terminal
go test -count=1 ./...
# or clear the cache explicitly
go clean -testcache

Make tests depend on tracked inputs

  1. Prefer in-package fixtures and testdata/ so changes invalidate the cache.
  2. Inject configuration through code the test imports, not untracked env vars.
  3. Reserve -count=1 for suites that genuinely must re-run each time.

How to prevent it

  • Use -count=1 in CI when you need guaranteed fresh runs.
  • Keep test inputs inside the package (testdata/) so the cache key tracks them.
  • Avoid hidden external dependencies that the cache cannot see.

Frequently asked questions

What causes ""(cached)" test results"?
The test cache keys on source, dependencies, and a known set of inputs. A test that reads an untracked env var, network service, or external file can be cached even though that input changed.
How do I fix "(cached)" test results?
Disable the cache for runs that must execute every time.

Related guides

References

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