---
title: "go test printed \"(cached)\": did the tests run on this commit? | Proofline"
description: "A (cached) line means Go replayed an earlier passing result instead of running the test binary."
url: https://proofline.sh/learn/go-test-cached-result/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# go test printed "(cached)": did the tests run on this commit?

A (cached) line means Go replayed an earlier passing result instead of running the test binary. Go reuses it only when the test binary, the flags, and the files and environment variables the test read are unchanged, so for code alone it is sound. It cannot see a database, a service or anything else the test reached over the network. When a test's verdict depends on something outside the module, run it with -count=1 before you count it as evidence.

Code review The Proofline team December 2, 2026 3 min read

## What the cache keys on

The `go test` documentation says that in package list mode (`go test .`, `go test ./...`) Go caches successful package results and prints `(cached)` in place of the elapsed time. A cached result matches when "the run involves the same test binary" and the flags come from a short list of cacheable ones. "Tests that open files within the package's module or that consult environment variables only match future runs in which the files and environment variables are unchanged." The idiomatic way to disable caching is `-count=1`. [go test caching](https://pkg.go.dev/cmd/go#hdr-Test_packages)

The same text leaves out everything else. A test that calls an HTTP endpoint, queries a database or reads a file outside the module is replayed even if that answer changed.

## Fixture: what the cache noticed and what it missed

Go 1.26.11 in `golang:1.26`. The package has three tests: one reads `testdata/limit.txt`, one reads `REGION`, and one calls a local HTTP service that answers `ok`. The service then starts answering `broken`:

```
$ go test .
ok  	example.com/app	0.016s
exit 0
$ go test .
ok  	example.com/app	(cached)
exit 0
$ echo broken > answer file served by the service
$ go test .
ok  	example.com/app	(cached)
exit 0
$ go test -count=1 .
--- FAIL: TestService (0.00s)
    app_test.go:25: service said "broken\n"
FAIL
FAIL	example.com/app	0.010s
FAIL
exit 1
$ echo 200 > testdata/limit.txt
$ go test .
--- FAIL: TestLimitFile (0.00s)
[…]
$ REGION=us go test .
ok  	example.com/app	0.009s
exit 0
```

Changing the test data and the environment variable each made Go run the binary again. Breaking the service did not: the third run replayed a pass and exited 0 while the service it tests was failing.

## Why this reaches CI

`actions/setup-go` caches `GOCACHE` and `GOMODCACHE` by default; [the README](https://github.com/actions/setup-go#caching-dependency-files-and-build-outputs) says caching "is enabled by default", and the action's [cache paths](https://github.com/actions/setup-go/blob/main/src/package-managers.ts) come from `go env GOCACHE` and `go env GOMODCACHE`. Go keeps test results in that build cache; `go clean -testcache` "removes all cached test results (but not cached build results)". [Build and test caching](https://pkg.go.dev/cmd/go#hdr-Build_and_test_caching)

So a CI job on a new commit can print `(cached)` for a package whose code did not change, using a result recorded by an earlier run. For pure code that is a correct reuse. For an integration test, the cached result describes the service and data as they were when that earlier run happened.

## Decide which tests may be cached

| Test reads | Cached result is | Run with |
| --- | --- | --- |
| Only code and files in the module | Valid for this binary | `go test ./...` |
| Environment variables | Valid if the values match | `go test ./...` |
| A database, service, cloud API or file outside the module | Stale evidence | `-count=1` |
| The clock or random values | A replay of one earlier outcome | `-count=1`, or fix the test |

`-count=1` is the simplest switch for an integration job. Before it, run `GODEBUG=gocachetest=1 go test ./...`, which the documentation says prints details of each decision to reuse a cached result. When you hand a result on, quote the `ok` line with its elapsed time. If the line says `(cached)`, write in the handoff that this job did not run those tests.

For counting what actually ran, see [a test command that ran no tests](/learn/filtered-test-run-zero-tests/). Turborepo has its own form of replay: [a cache hit with an undeclared variable](/learn/turborepo-cache-hit-undeclared-env/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [The test command passed because it ran no tests](/learn/filtered-test-run-zero-tests/)
    
    Code review The Proofline team November 24, 2026 3 min read
    
-   ### [Turborepo replayed a build made with another API URL](/learn/turborepo-cache-hit-undeclared-env/)
    
    Code review The Proofline team December 2, 2026 3 min read
