Go CLI Testing and Benchmarks

go test patterns for package tests, focused runs, benchmarks, fuzzing, coverage, JSON output, and CI-friendly test workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Test Basics

Test Basics commands and patterns for the Go command.

Test all packages

Run tests for all packages in the module.

bashANYgotest
bash
go test ./...

Run tests for all packages in the module. Useful in Go CLI workflows.

Verbose tests

Print each test as it runs.

bashANYgotestverbose
bash
go test -v ./...

Print each test as it runs. Useful in Go CLI workflows.

Run matching tests

Run only tests whose names match a regexp.

bashANYgotestfilter
bash
go test -run TestHTTP ./...

Run only tests whose names match a regexp. Useful in Go CLI workflows.

Disable test cache

Force tests to run instead of using cached results.

bashANYgotestcache
bash
go test -count=1 ./...

Force tests to run instead of using cached results. Useful in Go CLI workflows.

Stop on first failure

Abort package test execution after the first failure.

bashANYgotest
bash
go test -failfast ./...

Abort package test execution after the first failure. Useful in Go CLI workflows.

Benchmarks

Benchmarks commands and patterns for the Go command.

Run benchmarks

Run benchmarks matching a regexp.

bashANYgobench
bash
go test -bench=. ./...

Run benchmarks matching a regexp. Useful in Go CLI workflows.

Set benchmark time

Control how long each benchmark runs.

bashANYgobench
bash
go test -bench=. -benchtime=3s ./...

Control how long each benchmark runs. Useful in Go CLI workflows.

Show alloc stats

Include memory allocation stats in benchmark output.

bashANYgobenchmemory
bash
go test -bench=. -benchmem ./...

Include memory allocation stats in benchmark output. Useful in Go CLI workflows.

Benchmark specific package

Benchmark current package only.

bashANYgobench
bash
go test -run=^$ -bench=BenchmarkParse .

Benchmark current package only. Useful in Go CLI workflows.

Coverage

Coverage commands and patterns for the Go command.

Cross-package coverage

Measure coverage for multiple packages while testing one package set.

bashANYgocoverage
bash
go test -coverpkg=./... ./...

Measure coverage for multiple packages while testing one package set. Useful in Go CLI workflows.

Write coverage profile

Write a cover profile for later analysis.

bashANYgocoverage
bash
go test -coverprofile=coverage.out ./...

Write a cover profile for later analysis. Useful in Go CLI workflows.

Summarize coverage file

Show function-by-function coverage from a profile.

bashANYgocoverage
bash
go tool cover -func=coverage.out

Show function-by-function coverage from a profile. Useful in Go CLI workflows.

Open HTML coverage

Render an HTML coverage report.

bashANYgocoverage
bash
go tool cover -html=coverage.out

Render an HTML coverage report. Useful in Go CLI workflows.

Fuzzing

Fuzzing commands and patterns for the Go command.

Run fuzz target

Run or continue fuzzing for a matching fuzz target.

bashANYgofuzz
bash
go test -fuzz=FuzzParse

Run or continue fuzzing for a matching fuzz target. Useful in Go CLI workflows.

Limit fuzz duration

Run fuzzing for a bounded amount of time.

bashANYgofuzz
bash
go test -fuzz=FuzzParse -fuzztime=30s

Run fuzzing for a bounded amount of time. Useful in Go CLI workflows.

Run fuzz seed corpus

Run only seed inputs in a fuzz test.

bashANYgofuzz
bash
go test -run=FuzzParse

Run only seed inputs in a fuzz test. Useful in Go CLI workflows.

CI and Machine Output

CI and Machine Output commands and patterns for the Go command.

Emit JSON test events

Generate machine-readable test events.

bashANYgotestjson
bash
go test -json ./...

Generate machine-readable test events. Useful in Go CLI workflows.

Shuffle test order

Detect order-dependent tests by shuffling.

bashANYgotest
bash
go test -shuffle=on ./...

Detect order-dependent tests by shuffling. Useful in Go CLI workflows.

Set timeout

Fail tests that exceed a timeout.

bashANYgotest
bash
go test -timeout=2m ./...

Fail tests that exceed a timeout. Useful in Go CLI workflows.

Limit parallel tests

Set max parallel tests in a package.

bashANYgotest
bash
go test -parallel=4 ./...

Set max parallel tests in a package. Useful in Go CLI workflows.

Recommended next

No recommendations yet.