Test and benchmark Go code
8 steps · about 4 h 15 min · Intermediate
- Write a first Go test (guide, Go documentation, 30 min)
Connect the testing package, naming convention and go test command in a tiny module.
- Understand the testing package (reference, Go packages, 35 min)
Learn the contracts for tests, benchmarks, examples, helpers and cleanup.
- Organise table-driven cases (guide, Go Wiki, 30 min)
Represent inputs and expected results compactly while keeping failures readable.
- Isolate cases with subtests (guide, Go Blog, 30 min)
Name, filter and structure related cases without duplicating setup.
- Add a fuzz target (guide, Go documentation, 35 min)
Explore unexpected inputs while preserving discovered regressions as reusable cases.
- Interpret coverage (guide, Go Blog, 25 min)
Use uncovered paths to guide questions without treating percentage as proof of correctness.
- Run the race detector (guide, Go documentation, 30 min)
Find unsafe concurrent access under realistic tests and understand its runtime trade-offs.
- Benchmark before optimising (guide, Go Blog, 40 min)
Write repeatable benchmarks and profile the measured bottleneck instead of guessing.