golang-testing

Write Go tests using table-driven patterns, subtests, benchmarks, fuzzing, and coverage analysis.

37|4|Updated Apr 11, 2026
One-click install
npx skills add https://github.com/jmrplens/gitlab-mcp-server --skill golang-testing-jmrplens
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/jmrplens/gitlab-mcp-server/tree/main/.github/skills/golang-testing
Command: npx skills add https://github.com/jmrplens/gitlab-mcp-server --skill golang-testing-jmrplens

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing idiomatic, maintainable Go tests requires knowing many patterns—table-driven tests, subtests, golden files, mocking, benchmarks, and fuzzing—and this Skill consolidates them into one TDD-oriented reference so tests are written correctly the first time. ## Core Features & Use Cases - Table-Driven Tests & Subtests: Standard Go patterns for comprehensive case coverage, including parallel subtests and error-case handling. - Benchmarks & Fuzzing: Performance benchmarks with b.Loop(), memory allocation measurement, and Go 1.18+ fuzz tests with seed corpora. - Coverage & CI Integration: Coverage profiling commands, per-function reports, and CI gating aligned with this project's 90% coverage threshold. - Use Case: When adding a new HTTP handler to a Go service, use this Skill to generate a table-driven httptest suite with proper status and body assertions, plus a benchmark for the hot path. ## Quick Start Write table-driven unit tests with subtests and coverage for my new Go function in parser.go.

Frequently Asked Questions about golang-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write table-driven tests in Go?

Define a slice of anonymous structs with name, inputs, and expected outputs, then loop over it calling t.Run(tt.name, ...) for each case. This pattern gives one subtest per case with clear failure output and minimal code duplication.

How to run benchmarks and measure memory allocations in Go?

Write a BenchmarkXxx function taking *testing.B and loop with b.Loop() (Go 1.24+) or for i := 0; i < b.N; i++. Run with go test -bench=. -benchmem to report ns/op, bytes per operation, and allocations per operation.

Does Go support fuzz testing natively?

Yes, Go 1.18+ includes built-in fuzzing via testing.F. Add seed inputs with f.Add(), define the fuzz function with f.Fuzz(), and run it using go test -fuzz=FuzzName -fuzztime=30s to discover edge-case inputs automatically.

Why does t.Fatal fail inside an httptest handler or goroutine?

t.Fatal and t.Fatalf only terminate the calling goroutine, so inside a handler or spawned goroutine they truncate the response without failing the test properly. Use t.Errorf plus return, or record errors with atomics and assert on the main test goroutine.

How do I check Go test coverage in CI?

Run go test -race -coverprofile=coverage.out ./... then inspect with go tool cover -func=coverage.out. Parse the total percentage and fail the pipeline if it falls below your threshold, such as the 90% gate used in this project.