go-testing

Generates and diagnoses Go tests using testing, testify, and Uber Mock.

Updated Jul 6, 2026
One-click install
npx skills add https://github.com/chenziyang110/launchdeck --skill go-testing-chenziyang110
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go-testing
Source: https://github.com/chenziyang110/launchdeck/tree/main/.claude/skills/go-testing
Command: npx skills add https://github.com/chenziyang110/launchdeck --skill go-testing-chenziyang110

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing idiomatic, reliable Go tests requires choosing the right patterns—table-driven tests, mocks, fuzzing, race detection—and avoiding flaky or meaningless assertions. This Skill provides a structured workflow for generating, fixing, and improving Go test suites. ## Core Features & Use Cases - Test Generation: Produces table-driven tests, testify suites, mocks, HTTP handler tests with httptest, fuzz tests, and benchmarks following Go 1.21+ conventions. - Failure Diagnosis: Guides debugging of failing or flaky tests using -race, -count=1, and synchronization best practices. - Coverage & CI Integration: Sets up coverage profiling, coverage gates, and GitHub Actions test workflows. - Use Case: Ask the agent to write tests for an HTTP handler, and it analyzes the code, selects httptest with table-driven cases, generates the test file, and provides the exact go test commands to verify. ## Quick Start Ask the agent to write table-driven tests with testify assertions for a specific Go package or function in your project.

Frequently Asked Questions about go-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 structs with name, inputs, and expected outputs, then loop with t.Run(tt.name, ...) for each case. Add t.Parallel() for concurrency, but reassign the loop variable (tt := tt) first to avoid capturing it by reference.

How do I mock interfaces in Go tests?▼

Use testify's mock package by embedding mock.Mock and defining expected calls with On() and Return(), or generate mocks with Uber's mockgen from go.uber.org/mock. The original github.com/golang/mock is archived, so use the Uber fork.

How do I test HTTP handlers in Go?▼

Use httptest.NewRequest to build a request and httptest.NewRecorder to capture the response, then call your handler directly and assert on the recorder's Code and Body. For full server behavior, use httptest.NewServer.

Why are my Go tests flaky and how do I fix them?▼

Flakiness usually comes from time.Sleep synchronization, shared state, or real time/network dependencies. Replace sleeps with sync.WaitGroup or channels, use t.TempDir() for isolation, and reproduce with go test -count=10 -race.

How do I measure Go test coverage in CI?▼

Run go test -coverprofile=coverage.out -covermode=atomic ./... then use go tool cover -func=coverage.out for per-function percentages or -html for a visual report. Add -race -count=1 in CI to disable caching and detect data races.

When should I not use mocks in Go testing?▼

Avoid mocks when testing pure functions or when over-mocking couples tests to implementation details. Prefer fakes like in-memory stores for collaborators, and use integration tests with dockertest or testcontainers for real database behavior.