Skip to content

Testing: resources

Where the claims in this chapter come from, and where to read further. Everything in the chapter was measured on Go 1.25; the sources below say what the tools promise, and the books say how their authors use them.

Primary sources

Books

  • Alan A. A. Donovan and Brian W. Kernighan, The Go Programming Language (Addison-Wesley, 2015), chapter 11, "Testing" — 11.1, "The go test Tool"; 11.2, "Test Functions", with 11.2.1, "Randomized Testing" (the hand-rolled ancestor of a fuzz target), 11.2.4, "External Test Packages", 11.2.5, "Writing Effective Tests" and 11.2.6, "Avoiding Brittle Tests"; 11.3, "Coverage"; 11.6, "Example Functions". Written for Go 1.5: no subtests, no t.Cleanup, no fuzzing — the sections on what a good test looks like have not aged.
  • Jon Bodner, Learning Go, 2nd ed. (O'Reilly, 2024), chapter 15, "Writing Tests" — "Understanding the Basics of Testing" with "Reporting Test Failures", "Setting Up and Tearing Down", "Testing with Environment Variables", "Storing Sample Test Data", "Caching Test Results" and "Testing Your Public API"; then "Running Table Tests", "Running Tests Concurrently", "Checking Your Code Coverage", "Fuzzing", "Using Integration Tests and Build Tags" and "Finding Concurrency Problems with the Data Race Detector". The closest match to this chapter, section for section.
  • Go in Practice, 2nd ed. (Manning, 2025), chapter 6, "Formatting, testing, debugging, and benchmarking" — 6.3, "Unit testing in Go": "Creating a test suit with table-driven tests", "Fuzzing test input", "Annotating tests with names" and "Checking test coverage with go cover".
  • Adam Freeman, Pro Go (Apress, 2022), chapter 31, "Unit Testing, Benchmarking, and Logging" — "Using Testing", with "Running Unit Tests" and "Managing Test Execution" (-run, -v, t.Fatal against t.Error, t.Skip).
  • Miki Tebeka, Effective Go Recipes (Pragmatic Bookshelf, 2024), chapter 13, "Testing Your Code" — recipe 65, "Conditionally Running Continuous Integration Tests" (testing.Short and environment checks), recipe 66, "Reading Test Cases from a File", recipe 67, "Fuzzing Bugs Away", recipe 69, "Writing Global Setup/Teardown Functions" (TestMain).

Not on the shelf

  • Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning, 2022) — 100go.co ↗: a chapter of testing mistakes, among them parallel tests that share state, t.Cleanup against defer, and not using table-driven tests.

Talks and videos

  • Advanced Testing with Go — Mitchell Hashimoto, GopherCon 2017 (YouTube ↗): table-driven tests, testdata/, golden files, test helpers and t.Helper.
  • Testing in Go — Rob Pike's account of the design runs through The cover story ↗; for fuzzing, Go Fuzzing — Katie Hockman, GopherCon 2022 (YouTube ↗), the engine's design and what to fuzz.

Read with care

  • Any subtest loop with c := c (or tc := tc) as its first line: needed before Go 1.22 for parallel subtests, harmless and confusing after — Go 1.22 release notes ↗.
  • Advice to use t.Setenv in a test that also calls t.Parallel, or to "save and restore" os.Setenv by hand around a parallel test: the first panics since Go 1.17, and the second is a data race; Parallel subtests wait, Cleanup runs last.
  • Tutorials whose go test transcripts show a -2 suffix on test names under -cpu: benchmarks get the suffix, tests do not (measured in the same lesson).
  • Descriptions of the test cache that say -count=1 "clears" it: nothing is cleared, the run is not served from it; go clean -testcache clears it.
  • testing.T passed by value in a helper: it compiles, and the vet page shows a --- PASS next to a FAIL.

Checked 2026-09-23.