Test and benchmark Go code

8 steps · about 4 h 15 min · Intermediate

  1. Write a first Go test (guide, Go documentation, 30 min)

    Connect the testing package, naming convention and go test command in a tiny module.

  2. Understand the testing package (reference, Go packages, 35 min)

    Learn the contracts for tests, benchmarks, examples, helpers and cleanup.

  3. Organise table-driven cases (guide, Go Wiki, 30 min)

    Represent inputs and expected results compactly while keeping failures readable.

  4. Isolate cases with subtests (guide, Go Blog, 30 min)

    Name, filter and structure related cases without duplicating setup.

  5. Add a fuzz target (guide, Go documentation, 35 min)

    Explore unexpected inputs while preserving discovered regressions as reusable cases.

  6. Interpret coverage (guide, Go Blog, 25 min)

    Use uncovered paths to guide questions without treating percentage as proof of correctness.

  7. Run the race detector (guide, Go documentation, 30 min)

    Find unsafe concurrent access under realistic tests and understand its runtime trade-offs.

  8. Benchmark before optimising (guide, Go Blog, 40 min)

    Write repeatable benchmarks and profile the measured bottleneck instead of guessing.