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 (cache is bypassed with -count=1). It runs go vet automatically on the package before testing, and 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.
INSTALL
sudo apt install gccgo-go
sudo dnf install gcc-go
sudo pacman -S gcc-go
sudo apk add gcc-go
sudo zypper install gcc-go
brew install go
nix profile install nixpkgs#go
CAVEATS
Cached results are reused for unchanged tests unless -count=1 is set. Only functions matching `Test*`, `Benchmark*`, `Example*`, and `Fuzz*` in `*_test.go` files are recognized.
