liveBook · Manning

Go test

go test is the Go command that builds and runs tests for specified packages and can also execute benchmarks and report coverage.

How 4 Manning books explain it

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.

Read how Go in Action, Second Edition explains go test →

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.

Read how Go in Practice, Second Edition explains go test →

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.

Read how Go by Example explains go test →

Also covered in

What to know first

Related concepts

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.