go-testing-mistakes

Eliminate common Go testing mistakes across unit, benchmark, and integration tests.

15|Updated Mar 4, 2026
One-click install
npx skills add https://github.com/v0lka/skills --skill go-testing-mistakes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-testing-mistakes
Source: https://github.com/v0lka/skills/tree/main/development/idiomatic-go/go-testing-mistakes
Command: npx skills add https://github.com/v0lka/skills --skill go-testing-mistakes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go testing mistakes cause flaky tests, slow feedback, and brittle test suites. This guide helps teams identify and fix these pitfalls across unit, benchmark, and integration tests.

Core Features & Use Cases

  • Test categorization: apply build tags, env vars, and short mode to separate test kinds and speeds.
  • Race detection and execution: consistently run tests with -race and leverage parallel subtests with t.Parallel.
  • Table-driven tests: implement robust table-driven tests with proper variable capture and subtests.
  • Avoid sleeps and ensure determinism: replace time.Sleep with polling or channel synchronization; inject time dependencies for deterministic tests.
  • Benchmark discipline: structure benchmarks with proper timer control, multiple runs, and guard against compiler optimizations.
  • Utilize testing utilities: use httptest and iotest for HTTP and IO testing.

Quick Start

Audit your current Go tests and apply the recommended patterns to improve correctness and reliability.

Frequently Asked Questions about go-testing-mistakes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why are my Go tests flaky and how do I fix time-based dependencies?

Go tests become flaky when using time.Sleep. Fix this by replacing sleeps with channel synchronization or polling, and inject time dependencies to ensure deterministic test execution.

How do I write robust table-driven tests in Go with proper variable capture?

Write robust table-driven tests in Go by iterating over test cases and running each as a subtest. Ensure proper variable capture by re-declaring the loop variable inside the loop body to avoid closure bugs.

What is the best way to structure Go benchmarks and avoid compiler optimizations?

Structure Go benchmarks by controlling the timer with b.ResetTimer and running multiple iterations. Guard against compiler optimizations by consuming benchmark outputs in the runtime to prevent dead code elimination.

How do I categorize and separate slow integration tests from unit tests in Go?

Categorize Go tests by applying build tags, environment variables, and the testing.Short flag. This separates slow integration tests from fast unit tests, allowing you to run quick feedback loops during development.

How do I safely parallelize Go subtests using t.Parallel?

Safely parallelize Go subtests by calling t.Parallel at the start of each subtest. Ensure table-driven test cases capture their own variables to prevent race conditions during concurrent execution.

What utilities can I use for testing HTTP and IO operations in Go?

Use the standard library testing utilities httptest for mocking HTTP servers and clients, and iotest for simulating IO errors and edge cases to ensure comprehensive coverage for network and data operations.