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
- Uses the bundled test runner to check package behavior, find coverage gaps, benchmark code, and detect races.
- How deep it goes
- Explains test discovery, execution and selection, then walks through coverage profiles and browser inspection.
- Examples
- Uses a calculator memory recovery test and benchmarks comparing random-string implementations.
- What you can do after
- Apply it via go test to select tests, inspect coverage, run benchmarks, and check for races.
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 to check behavior as code changes.
- How deep it goes
- Explains output checks, explicit failure reporting, table-driven tests, and parallel execution; notes that an ordinary passing run can miss a data race.
- Examples
- Uses greeting output and return-value tests, plus parallel subtests writing different values to one cache index.
- What you can do after
- Apply it via go test to run package tests and report mismatches 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.
Also covered in
- Shipping Go: Develop, deliver, discuss, design, and go again
- React Quickly, Second Edition
- Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu
What to know first
- GoGo is a statically typed, compiled, general-purpose programming language with garbage collection and built-in support for concurrency.
- software testingSoftware testing is the systematic evaluation of software under specified inputs or conditions to assess its behavior against expected results or requirements and identify defects.
- benchmarkA benchmark is a defined, repeatable task, workload, test, dataset, or reference standard used to measure or compare systems or methods under specified conditions.
- regular expressionA regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
Related concepts
- benchmarkused by · A benchmark is a defined, repeatable task, workload, test, dataset, or reference standard used to measure or compare systems or methods under specified conditions.
- race conditionmeasures · A race condition is a concurrency defect in which program behavior or results depend on the 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 is a measure of which portions or behaviors of a program are exercised during testing.
- regular expressionuses · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
Questions about go test
What is go test?
go test is the Go command that builds and runs tests for specified packages and can also execute benchmarks and report coverage.
Which Manning books explain go test?
Go in Action, Second Edition, Learn Go with Pocket-Sized Projects, Go in Practice, Second Edition and Go by Example.
What should I know before learning go test?
Manning books that teach go test usually introduce Go, software testing, benchmark and regular expression first.
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.



