golang-pitfalls-testing
Installation
SKILL.md
Golang Pitfalls: Testing & Benchmarks
Source material: mistakes #82-90 (plus community fuzzing) from 100 Go Mistakes and How to Avoid Them (teivah/100-go-mistakes).
Apply these rules when writing Go tests and benchmarks.
82. Not categorizing tests (#82)
- Categorize with build tags, environment variables, or short mode to separate unit vs. integration vs. long-running tests.
- Example: gate slow tests behind
-short(if testing.Short() { t.Skip(...) }) or separate files with//go:build integration.
83. Not enabling the race flag (#83)
- Run tests with the race detector:
go test -race ./.... - It instruments memory accesses at runtime (not static analysis) and detects data races in concurrent tests, with added memory/time overhead — enable it locally and in CI, not production.
- Reading a
WARNING: DATA RACEreport: it lists the concurrent goroutines, the offending read/write locations in code, and where the goroutine was created. - You can exclude a specific test file from race detection with
//go:build !race(temporarily).