golang-testing

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

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill golang-testing-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/golang-testing
Command: npx skills add https://github.com/ibytechaos/claude --skill golang-testing-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing thorough, idiomatic Go tests requires knowing many patterns—table-driven tests, subtests, mocks, benchmarks, and fuzzing—and developers often skip coverage or write brittle tests without a clear TDD workflow. ## Core Features & Use Cases - Table-Driven Test Patterns: Provides templates for table-driven tests with error cases, subtests, and parallel execution using t.Run and t.Parallel. - Benchmarks and Fuzzing: Includes benchmark patterns with memory allocation tracking and Go 1.18+ fuzz tests with seed corpora and property-based assertions. - Coverage and CI Integration: Covers go test coverage commands, race detection, golden file testing, HTTP handler testing with httptest, and GitHub Actions CI setup. - Use Case: When implementing a new Go function, follow the RED-GREEN-REFACTOR cycle: write a failing table-driven test first, implement minimal code to pass, then refactor while keeping tests green. ## Quick Start Ask the assistant to write table-driven unit tests with benchmarks and fuzz tests 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 name, inputs, and expected outputs, then loop over it calling t.Run for each case. This pattern covers many scenarios 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 each interface method. Inject the mock into the code under test and set the function fields to return canned responses per test case.

Does go test support code coverage reports?

Yes, 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 for race detection.

Why should I avoid testing private functions in Go?

Testing private functions couples tests to implementation details, making refactors break tests unnecessarily. Test through the public API instead, which verifies behavior rather than internal structure.

How do I test HTTP handlers in Go?

Use httptest.NewRequest to build a request and httptest.NewRecorder to capture the response, then call the handler directly. Assert on the recorder's status code and body, optionally using table-driven tests for multiple endpoints.