go-test
Go package testing framework
TLDR
Run tests in current package
$ go test
Run tests with verbose output$ go test -v
Run specific tests by pattern$ go test -run [TestName]
Run benchmarks$ go test -bench .
Run with race detector$ go test -race
Run with coverage$ go test -cover
Generate coverage profile$ go test -coverprofile=[coverage.out]
Run tests in all packages$ go test ./...
SYNOPSIS
go test [build/test flags] [packages] [flags for test binary]
DESCRIPTION
go test automates testing of Go packages. It compiles and runs test files (*_test.go) containing functions named Test*, Benchmark*, and Example*. Tests can run in parallel, include race detection, and generate coverage reports.
The command recompiles packages as needed and caches successful test results. It supports subtests, table-driven tests, and fuzz testing for comprehensive validation.
PARAMETERS
-v
Verbose output.-run regexp
Run only tests matching pattern.-bench regexp
Run benchmarks matching pattern.-cover
Enable coverage analysis.-coverprofile file
Write coverage to file.-race
Enable race detector.-count n
Run each test n times.-timeout d
Test timeout (default 10m).-short
Tell tests to shorten long operations.-parallel n
Max parallel test execution.-json
Output results as JSON.
