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

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

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

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

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

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=. ./...
Notes

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

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

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

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=./... ./...
Notes

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

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
Notes

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
Notes

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
Notes

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
Notes

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
Notes

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

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

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

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

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

Recommended next

No recommendations yet.