LinuxCommandLibrary

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

SEE ALSO

go(1), go-build(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community