writing-go-tests

Enforce Go testing best practices for unit and integration tests.

3|Updated Nov 12, 2025
One-click install
npx skills add https://github.com/torosent/crankfire --skill writing-go-tests-torosent
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-go-tests
Source: https://github.com/torosent/crankfire/tree/main/.claude/skills/writing-go-tests
Command: npx skills add https://github.com/torosent/crankfire --skill writing-go-tests-torosent

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides actionable Go testing guidelines to write, review, and improve tests, helping teams achieve meaningful coverage and robust test suites without reliance on external tools.

Core Features & Use Cases

  • Test Organisation: Recommend adjacent, per-function test files and proper package usage.
  • Table-Driven Testing: Promote map-based table-driven tests with descriptive names.
  • Concurrency Testing Guidance: Advise patterns for deterministic concurrent tests and proper use of t.Parallel().
  • Assertions & Comparisons: Suggest appropriate assertion strategies and diffing approaches.
  • Mocks vs Integration: Recommend when to mock and when to use real dependencies with integration tests.
  • Coverage & Fixtures: Guidance on test fixtures, golden files, and meaningful coverage targets.

Quick Start

Apply current Go testing best practices to this repository's tests. Example prompt: "Review this Go project and apply Table-Driven, Concurrency, and Coverage best practices."

Frequently Asked Questions about writing-go-tests

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 use a slice of test cases with inputs and expected outputs, executed in a loop. This pattern reduces code duplication, improves readability, and makes it easy to add new test cases without duplicating test logic.

What's the best way to organize Go test files in my project?

Place test files adjacent to the code they test, using the `_test.go` suffix. Use internal tests (same package) for whitebox testing and external tests (package_test) for blackbox testing and avoiding import cycles.

How do I test concurrent code in Go without flakiness?

Use `t.Parallel()` to mark independent tests, employ synchronization primitives like `sync.WaitGroup` for deterministic coordination, and avoid time-dependent assertions. This ensures tests are reliable and leverage concurrent execution.

When should I mock dependencies versus using integration tests?

Mock external services and slow dependencies to isolate units; use integration tests for critical data flows and cross-service interactions. Mocking speeds up test suites; integration tests catch real-world failures.

What coverage targets should my Go tests aim for?

Aim for meaningful coverage of critical paths and error handling rather than chasing a percentage. Use `go test -cover` to measure coverage, focus on uncovered branches, and prioritize business logic and edge cases.

How do I use benchmarks to measure Go performance?

Write benchmark functions with `func Benchmark*` signature and use `testing.B` to run iterations. Run with `go test -bench` to compare performance across changes and identify bottlenecks in production code.