golang-testing

Implements Go testing patterns including table-driven tests, benchmarks, fuzzing, and coverage analysis.

Updated May 19, 2026
One-click install
npx skills add https://github.com/azusagasaku/--claude-config --skill golang-testing-azusagasaku
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/azusagasaku/--claude-config/tree/main/skills/ecc/golang-testing
Command: npx skills add https://github.com/azusagasaku/--claude-config --skill golang-testing-azusagasaku

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing thorough, maintainable Go tests requires knowing idiomatic patterns like table-driven tests, subtests, golden files, and fuzzing, which many developers apply inconsistently or skip entirely. ## Core Features & Use Cases - TDD Workflow Guidance: Walks through the RED-GREEN-REFACTOR cycle with concrete Go code examples for test-first development. - Comprehensive Test Patterns: Covers table-driven tests, parallel subtests, test helpers, golden files, interface-based mocking, and HTTP handler testing with httptest. - Performance & Robustness Testing: Provides benchmark patterns with memory allocation tracking and Go 1.18+ fuzz tests with property-based assertions. - Use Case: When adding coverage to a Go microservice, use this Skill to generate table-driven unit tests, set up mocks for repository interfaces, run race detection, and enforce an 80% coverage gate in CI. ## Quick Start Write table-driven unit tests with subtests and coverage reporting for my Go package in the current directory.

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 holding test case inputs and expected outputs, then loop over them calling t.Run with each case name. This pattern gives comprehensive coverage with minimal code and clear failure messages per case.

How to run fuzz tests in Go?▼

Write a function starting with Fuzz that takes *testing.F, add seed corpus inputs with f.Add, then define the fuzz function with f.Fuzz. Run it with go test -fuzz=FuzzName -fuzztime=30s, which requires Go 1.18 or later.

How do I mock dependencies in Go tests?▼

Define an interface for the dependency, then create a mock struct with function fields matching each interface method. Tests inject the mock and set behavior per case, avoiding external libraries for most scenarios.

Does Go testing support parallel test execution?▼

Yes, call t.Parallel() inside a test or subtest to run it concurrently with other parallel tests. Capture the range variable with tt := tt before the subtest to avoid sharing loop state across goroutines.

How do I measure test coverage in Go?▼

Run go test -coverprofile=coverage.out ./... to generate a coverage profile, then use go tool cover -html=coverage.out for a browser view or -func for per-function percentages. Combine with -race to detect data races during the same run.

Why are my Go tests flaky and how do I detect it?▼

Flakiness usually comes from time.Sleep calls, shared state, or uncontrolled concurrency. Replace sleeps with channels or conditions, and run go test -count=10 -race ./... to surface intermittent failures and data races.