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.
ok github.com/yourorg/app/api (cached)
ok github.com/yourorg/app/store (cached)
# tests did not actually execute this runCommon 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.
go test -count=1 ./...
# or clear the cache explicitly
go clean -testcacheMake tests depend on tracked inputs
- Prefer in-package fixtures and
testdata/so changes invalidate the cache. - Inject configuration through code the test imports, not untracked env vars.
- Reserve
-count=1for suites that genuinely must re-run each time.
How to prevent it
- Use
-count=1in 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.