golang-testing

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

Updated Apr 9, 2026
One-click install
npx skills add https://github.com/5onyy/essential-ai-agent-skills --skill golang-testing-5onyy
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/5onyy/essential-ai-agent-skills/tree/main/.cursor/skills/golang-testing
Command: npx skills add https://github.com/5onyy/essential-ai-agent-skills --skill golang-testing-5onyy

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 developers often produce inconsistent or incomplete test suites without a structured guide. ## Core Features & Use Cases - TDD Workflow Guidance: Walks through the RED-GREEN-REFACTOR cycle with concrete Go code examples for each step. - Comprehensive Test Patterns: Covers table-driven tests, parallel subtests, test helpers with t.Helper(), golden files, interface-based mocking, and HTTP handler testing with httptest. - Performance & Robustness Testing: Provides benchmark templates with memory allocation tracking and fuzz test examples for Go 1.18+ input validation. - Use Case: When adding a new parsing function to a Go service, use this Skill to generate a table-driven test with error cases, a fuzz test for malformed input, and a coverage report integrated into CI. ## Quick Start Write table-driven tests with benchmarks and fuzz coverage 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 containing test inputs and expected outputs, then loop over them calling t.Run for each case. 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 entries 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 measure Go test coverage?▼

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.

What is the best way to 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 only the functions they need, avoiding heavy mocking frameworks.

Why do my parallel Go subtests behave incorrectly?▼

Range loop variables are shared across iterations, so parallel subtests may capture the wrong value. Capture the variable with tt := tt before calling t.Parallel() inside the subtest closure.