LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

go-test

Go package testing framework

TLDR

Run tests in current package
$ go test
copy
Run tests with verbose output
$ go test -v
copy
Run specific tests by pattern
$ go test -run [TestName]
copy
Run benchmarks
$ go test -bench .
copy
Run with race detector
$ go test -race
copy
Run with coverage
$ go test -cover
copy
Generate coverage profile
$ go test -coverprofile=[coverage.out]
copy
Run tests in all packages
$ go test ./...
copy

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
copy
sudo dnf install gcc-go
copy
sudo pacman -S gcc-go
copy
sudo apk add gcc-go
copy
sudo zypper install gcc-go
copy
brew install go
copy
nix profile install nixpkgs#go
copy

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.

SEE ALSO

go(1), go-build(1)

RESOURCES

Copied to clipboard
Kai