Go test
go test is the Go command that builds and runs tests for specified packages and can also execute benchmarks and report coverage.
Go in Action, Second Edition
go test -cover is the Go test command mode that runs package tests and reports the percentage of statements they execute.
- How it is used
- Runs package tests with standardized Go tooling and reports statement coverage when invoked with `-cover`.
- How deep it goes
- Explains test discovery, execution, output, selection, and coverage reporting, including a worked coverage-driven bug fix.
- Examples
- Uses a passing logged test and a calculator recovery test that fails despite reaching 100% statement coverage.
- What you can do after
- Operate/configure it to run or select tests, inspect coverage, and investigate an uncovered calculator behavior.
Learn Go with Pocket-Sized Projects
The Go test framework is the standard framework that discovers, executes, and reports Go package tests.
- How it is used
- Runs package tests during development so changes can be checked against expected output and function results.
- How deep it goes
- Shows the command, output checks, testing.T failures, and parallel execution, but does not show how to detect the suspected race.
- Examples
- Uses a printed greeting, a string-returning greeting function, and parallel writes to one cache index.
- What you can do after
- Operate/configure it to rerun tests, verify Example output, and see failures reported with testing.T.
Read how Learn Go with Pocket-Sized Projects explains go test →
Go in Practice, Second Edition
go test is a Go command that compiles and runs tests for Go packages.
- How it is used
- Runs package tests to catch regressions, inspect coverage, and measure benchmark performance.
- How deep it goes
- Shows test naming and failure reporting, then gives commands for coverage profiles and benchmark selection without detailing runner internals.
- Examples
- Uses a failing string-reversal test, a coverage run over simple functions, and Bubble Sort benchmarks at several input sizes.
- What you can do after
- Practice/perform package testing, generate a coverage view, and run selected Go benchmarks.
Go by Example
go test is the Go command that builds and runs tests for Go packages.
- How it is used
- Runs, benchmarks, profiles, and manages Go package tests as part of the development workflow.
- How deep it goes
- Explains compilation, result caching, verbose output, and shuffle seeds, but defers detailed benchmark and profiling procedures.
- Examples
- Uses the url package with TestParse and TestURLString, plus cached, verbose, shuffled, and seed-reproduced command output.
- What you can do after
- Operate go test to run, inspect, rerun, shuffle, and reproduce Go package tests from the module directory.
Related concepts
- benchmarkused by · A benchmark is a defined task, dataset, workload, procedure, or reference measure used to assess or compare performance or capability under specified criteria or conditions.
- race conditionmeasures · A race condition is a concurrency defect in which program behavior or results depend on the relative timing or ordering of interacting operations.
- testing packageuses · The testing package is Go’s standard-library package for defining, running, and reporting automated tests and benchmarks.
- code coveragemeasures · Code coverage measures the extent to which a test suite exercises a program’s code elements, execution paths, or behaviors.
- regular expressionuses · A formal pattern notation that describes sets of strings and enables text to be matched, searched, extracted, or transformed.
- testuses · A test is a procedure or check that evaluates behavior using specified inputs or evidence against expected results or criteria.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



