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¶
testing↗ — the package documentation: "Subtests and Sub-benchmarks", "Examples", "Fuzzing", "Skipping", "Main", and the methodsT.Run,T.Parallel,T.Cleanup,T.TempDir,T.Setenv,T.Chdir,T.Context,T.Helper,T.FailNow. Settles what each method promises, and that a fuzz target without-fuzzruns its seed corpus only.go help test↗ — local directory mode against package list mode, the test cache and which flags are cacheable, the vet subsetgo testruns, and the external_testpackage.go help testflag↗ — every flag:-runand-skipsplit on/,-count,-cover,-coverprofile,-cpu,-failfast,-fuzz,-fuzztime,-json,-list,-parallel(defaultGOMAXPROCS),-shuffle,-short,-v,-vet.cmd/cover↗ and Coverage profiling support for integration tests ↗ — the profile format,-funcand-html, andgo build -coversince Go 1.20.- Go Fuzzing ↗ — the corpus file format, custom settings, requirements and limitations (AMD64 and ARM64); Tutorial: Getting started with fuzzing ↗.
cmd/test2json↗ — the eventsgo test -jsonemits.- The vet analyzers
go testruns and the ones it does not:tests↗,printf↗,testinggoroutine↗,waitgroup↗,copylocks↗. - The Go blog: Using Subtests and Sub-benchmarks ↗ (2016, subtests and
-runper level), Testable Examples in Go ↗ (2015,// Output:and how the documentation renders examples), The cover story ↗ (2013, how coverage is instrumented and what it does not measure), Fuzzing is Beta Ready ↗ (2021), Testing concurrent code with testing/synctest ↗ (2025, the subject of chapter 07). - Release notes, for when each piece arrived: Go 1.7 ↗ (subtests), Go 1.10 ↗ (the test cache,
-failfast,-json, the vet subset), Go 1.14 ↗ (Cleanup), Go 1.15 ↗ (TempDir), Go 1.17 ↗ (Setenv,-shuffle), Go 1.18 ↗ (fuzzing), Go 1.20 ↗ (-skip,go build -cover), Go 1.22 ↗ (the per-iteration loop variable, which retiredc := cin subtest loops), Go 1.24 ↗ (T.Context,T.Chdir,b.Loop), Go 1.25 ↗ (thewaitgroupanalyzer,WaitGroup.Go,[recovered, repanicked],synctest). - The source, for the messages the pages record:
src/testing/testing.goat go1.25.5 ↗ (Fail in goroutine after %s has completed,test using t.Setenv or t.Chdir can not use t.Parallel),src/testing/fuzz.go↗.
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.Fatalagainstt.Error,t.Skip). - Miki Tebeka, Effective Go Recipes (Pragmatic Bookshelf, 2024), chapter 13, "Testing Your Code" — recipe 65, "Conditionally Running Continuous Integration Tests" (
testing.Shortand 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.Cleanupagainstdefer, 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 andt.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(ortc := 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.Setenvin a test that also callst.Parallel, or to "save and restore"os.Setenvby 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 testtranscripts show a-2suffix 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 -testcacheclears it. testing.Tpassed by value in a helper: it compiles, and the vet page shows a--- PASSnext to aFAIL.
Checked 2026-09-23.