ecc-golang-testing

Write Go table-driven tests, benchmarks, fuzz targets, and HTTP handler tests following TDD patterns.

Updated Apr 18, 2025
One-click install
npx skills add https://github.com/adriancodes/dotfiles --skill ecc-golang-testing-adriancodes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ecc-golang-testing
Source: https://github.com/adriancodes/dotfiles/tree/main/dot_agents/skills/ecc-golang-testing
Command: npx skills add https://github.com/adriancodes/dotfiles --skill ecc-golang-testing-adriancodes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing thorough Go tests requires knowing idiomatic patterns for table-driven tests, subtests, mocks, benchmarks, and fuzzing, and this Skill provides a complete reference so you avoid reinventing test structure or missing error-path coverage. ## Core Features & Use Cases - Table-Driven Test Patterns: Standard Go test structures with error cases, subtests, parallel execution, and test helpers using t.Helper() and t.Cleanup(). - Benchmarks and Fuzzing: Templates for performance benchmarks with memory allocation tracking and Go 1.18+ fuzz targets with seed corpora and property-based assertions. - HTTP Handler Testing: Patterns for testing handlers with httptest.NewRequest and httptest.NewRecorder, plus golden file testing and coverage workflows. - Use Case: When adding tests to a Go API service, use this Skill to generate table-driven handler tests with mocks for the repository layer, then add a fuzz target for input validation. ## Quick Start Write table-driven unit tests with error cases and a benchmark for my Go ParseConfig function.

Frequently Asked Questions about ecc-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 inputs and expected outputs, then loop over it calling t.Run with each case name. Include a wantErr field to handle error cases, and use t.Helper() in shared assertion helpers.

How to write fuzz tests in Go?▼

Go 1.18+ supports fuzzing via testing.F: add seed inputs with f.Add, then define f.Fuzz with property-based assertions. Run it with go test -fuzz=FuzzName -fuzztime=30s to generate random inputs against your invariants.

How do I test HTTP handlers in Go without a server?▼

Use httptest.NewRequest to build a request and httptest.NewRecorder to capture the response, then call your handler directly. Assert on the recorder's Code and Body without starting a real network listener.

Does Go testing support parallel subtests?▼

Yes, call t.Parallel() inside a subtest to run it concurrently with other parallel subtests. Capture the loop variable before t.Run to avoid the classic range-variable aliasing bug.

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

Flakiness usually comes from shared state, time.Sleep calls, or data races. Run go test -race to detect races and go test -count=10 to repeat tests and surface intermittent failures.