golang-testing

Guide Go test authors to write reliable table-driven unit, integration, and concurrency tests.

2|Updated Feb 12, 2024
One-click install
npx skills add https://github.com/adibfirman/dotfiles --skill golang-testing-adibfirman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/adibfirman/dotfiles/tree/main/claude/.claude/skills/technical/golang/golang-testing
Command: npx skills add https://github.com/adibfirman/dotfiles --skill golang-testing-adibfirman

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of flaky, slow, and hard-to-maintain Go test suites by providing production-ready testing patterns that keep tests deterministic and behavior-focused.

Core Features & Use Cases

  • Table-driven tests with named subtests: Ensures every scenario is documented via a name field and executed through t.Run.
  • Safe parallelism: Encourages t.Parallel() for independent unit tests to keep runtimes low.
  • Correct separation of integration tests: Uses //go:build integration so integration code doesn’t compile or run during normal unit test runs.
  • Concurrency robustness: Adds goroutine leak detection using goleak and guidance for deterministic time/concurrency testing (e.g., testing/synctest).
  • Testing completeness: Covers unit, integration, fuzzing, snapshots/artifacts, mocks/interfaces, and executable Examples.

Quick Start

Use the golang-testing skill to generate or review a set of Go tests for your package, including edge cases, named table cases, and an integration-test build-tag layout when your package touches external systems.

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 with named subtests in Go?

Table-driven tests in Go use a struct slice of test cases with a name field, executed via t.Run to create named subtests. This pattern ensures every scenario is documented and runs as an isolated, identifiable test case within your suite.

What's the best way to separate integration tests from unit tests in Go?

Separate integration tests in Go using the //go:build integration build tag. This prevents integration code from compiling or running during normal unit test runs, keeping standard test execution fast and isolated from external systems.

How do I detect goroutine leaks in my Go tests?

Detect goroutine leaks in Go tests by integrating goleak for robust concurrency testing. It automatically verifies that goroutines are cleaned up after tests complete, ensuring deterministic behavior and preventing flaky test suites.

Why are my Go tests flaky when using t.Parallel?

Flaky Go tests using t.Parallel often stem from shared state, improper synchronization, or goroutine leaks. Ensure independent unit tests are truly stateless, apply goleak for leak detection, and use deterministic time testing like testing/synctest.

Can I use fuzzing and mocking together in a Go test workflow?

Fuzzing and mocking can be combined in a Go test workflow to achieve testing completeness. Fuzzing validates edge-case inputs while mocks and interfaces isolate dependencies, supported by executable Examples and coverage workflows.

Does this Go testing approach support PR reviews and flakiness auditing?

This Go testing approach applies to reviewing PR test changes and auditing for flakiness. It guides authors to write behavior-driven unit and integration tests, ensuring deterministic, production-ready patterns that scale reliably.