golang-testing

Generate Go testing patterns for table-driven tests, benchmarks, fuzzing, and HTTP handlers.

Updated Feb 5, 2026
One-click install
npx skills add https://github.com/gugug168/claudecode-tutorial --skill golang-testing-gugug168
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/gugug168/claudecode-tutorial/tree/main/everything-claude-code-learning/02-Skills/golang-testing
Command: npx skills add https://github.com/gugug168/claudecode-tutorial --skill golang-testing-gugug168

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides practical, idiomatic patterns and workflows to reduce flaky tests, improve coverage, and speed up development by teaching how to write maintainable Go tests that catch regressions early.

Core Features & Use Cases

  • Table-driven tests & subtests: Organize many scenarios concisely and run related checks with t.Run and t.Parallel for concurrency.
  • Benchmarks & memory profiling: Create b.N-driven benchmarks, measure allocations, and compare strategies for performance-critical code.
  • Fuzzing & input validation: Use fuzz tests to discover edge-case inputs and validate parsers or encoders for robustness.
  • HTTP handler testing & golden files: Validate server handlers with httptest and compare outputs against testdata golden files for complex formats.
  • CI integration & coverage: Generate coverage profiles, enforce targets in CI, and exclude generated code when appropriate.

Quick Start

Write a failing table-driven test for your new Go function, implement the minimal code to make it pass, and run go test to verify.

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?

Table-driven tests in Go organize multiple test scenarios concisely using slices of structs, executing each case with t.Run for subtests. This pattern enables parallel execution via t.Parallel and simplifies maintaining related checks.

How do I benchmark Go code and measure memory allocations?

Benchmark Go code by creating functions prefixed with Benchmark that utilize b.N for iterative execution. Measure memory allocations and compare performance strategies to optimize performance-critical code paths.

What is the best way to test HTTP handlers in Go?

Test HTTP handlers in Go using the httptest package to simulate requests and capture responses. Compare complex outputs against testdata golden files to verify server handler behavior accurately.

How do I generate coverage profiles and enforce targets in CI?

Generate coverage profiles by running go test with coverage flags, then parse the results to enforce targets in CI pipelines. Exclude generated code from coverage measurement when appropriate to maintain accuracy.

Why does my Go test flake during parallel execution?

Go tests flake during parallel execution due to shared state or unsynchronized data access. Ensure subtests using t.Parallel are completely isolated, avoiding shared variables and global dependencies to maintain reliable execution.