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
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.

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 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.

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 →

Related concepts

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.