golang-testing

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

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/erwinv2k-TKG/AgentesVSC --skill golang-testing-erwinv2k-tkg
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/erwinv2k-TKG/AgentesVSC/tree/main/packs/everything-claude-code/docs/zh-TW/skills/golang-testing
Command: npx skills add https://github.com/erwinv2k-TKG/AgentesVSC --skill golang-testing-erwinv2k-tkg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing thorough, idiomatic Go tests requires knowing many patterns—table-driven tests, subtests, mocks, benchmarks, fuzzing, and coverage tooling. This Skill provides a complete reference so you can apply TDD methodology and proven Go testing practices without searching documentation. ## Core Features & Use Cases - TDD Workflow Guidance: Follows the RED-GREEN-REFACTOR cycle with concrete Go code examples for each step. - Comprehensive Test Patterns: Covers table-driven tests, subtests, parallel tests, test helpers, golden files, interface-based mocks, and HTTP handler testing with httptest. - Performance & Robustness Testing: Includes benchmark patterns with memory allocation tracking and fuzz testing (Go 1.18+) for input validation. - Use Case: When adding tests to a Go API service, use this Skill to generate table-driven tests for handlers, mock the repository layer via interfaces, and set up coverage reporting in CI. ## Quick Start Ask the AI to write table-driven tests with benchmarks and coverage for your Go package following TDD methodology.

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 complete coverage with minimal code and is the standard Go testing idiom.

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; fuzzing 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 the interface methods. Inject the mock into the code under test, letting you control return values and errors per test case.

How do I check Go test coverage?

Run go test -coverprofile=coverage.out ./... to generate a coverage profile, then use go tool cover -func=coverage.out for per-function stats or go tool cover -html=coverage.out for a browser view. Combine with -race for race detection.

Why should I use t.Helper() in Go test helpers?

t.Helper() marks a function as a test helper so failure messages report the caller's line number instead of the helper's internal line. This makes debugging failing tests much faster when using shared setup or assertion functions.

When should I not use parallel subtests in Go?

Avoid t.Parallel() when subtests share mutable state like a single database connection or depend on execution order. Capture the loop variable before calling t.Parallel() to prevent all subtests from seeing the final iteration value.