Testing and Tooling
Testing, fuzzing, and core toolchain commands. Results appear in the same fence: same-line // comments when short, multiline // blocks below the sample when not.
Search across all documentation pages
Testing, fuzzing, and core toolchain commands. Results appear in the same fence: same-line // comments when short, multiline // blocks below the sample when not.
Run tests in package.
// go test ./...
// go test -run TestName -vSlice of cases with subtests.
tests := []struct{ in, out int }{{1, 2}, {2, 3}}
for _, tc := range tests {
if tc.in+1 != tc.out { panic("fail") }
}
// two cases passSubtests for naming and control.
// t.Run("name", func(t *testing.T) { ... })Native fuzzing entrypoint.
// func FuzzParse(f *testing.F) {
// f.Add("x")
// f.Fuzz(func(t *testing.T, s string) { _ = Parse(s) })
// }Static checks.
// go vet ./...BenchmarkXxx with b.N.
// func BenchmarkSum(b *testing.B) {
// for i := 0; i < b.N; i++ { sum() }
// }Mark helpers so failures point to caller.
// t.Helper()Per-test temp directory.
// dir := t.TempDir()Register cleanup callbacks.
// t.Cleanup(func() { ... })Run subtests in parallel carefully.
// t.Parallel()Examples as docs + tests.
// func ExampleAdd() {
// fmt.Println(Add(1, 2))
// // Output: 3
// }Profile coverage.
// go test -coverprofile=c.out ./...Format code.
// gofmt -w .Popular extra linter.
// staticcheck ./...Detect data races under test.
// go test -race ./...Stack versions: Go 1.26.x · chi/gin/echo latest (verify at build)
Reviewed by Chris St. John·Last updated Jul 18, 2026