go test
The go subcommand that builds a test binary from the _test.go files in a package, runs every test function and reports what failed.
In more detail
go test finds functions named TestSomething that take a *testing.T and runs them. The three-dot pattern after a path means that package and every package below it, so go test ./... tests a whole module. A non-zero exit code on failure lets a pipeline stop a bad release.
Examples
go test ./...go test -race ./...Related terms
- Go testing package — Go's standard library package for writing tests, run by the go test command.
- _test.go file — A Go source file whose name ends in _test.go, which holds tests and is compiled only by go test, never into your binary.
- table-driven test — A Go test style that lists many input cases and expected results as rows in a slice, then checks them all in one loop.
- go vet — The go subcommand that looks for code that compiles but is probably wrong, such as a print format verb that does not match its argument.
Taught in
- The Standard testing Package — Concurrent Systems Programming with Go
- Containerizing and Testing the Final Build — Concurrent Systems Programming with Go