golang-testing

Define Go testing best practices with table-driven tests and Testify mocks.

2.9k|191|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-testing-samber
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/samber/cc-skills-golang/tree/main/skills/golang-testing
Command: npx skills add https://github.com/samber/cc-skills-golang --skill golang-testing-samber

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a comprehensive guide to writing production-grade Go tests, helping teams build fast, reliable, and maintainable test suites.

Core Features & Use Cases

  • Table-driven tests with named subtests to ensure clarity and determinism.
  • Integration testing patterns, mocks (with Testify), benchmarks, code coverage, parallel tests, fuzzing, fixtures, goleak detection, and CI workflow guidance.
  • Go-specific testing patterns for libraries and services, including snapshot testing and memory-leak checks.

Quick Start

Install the skill and start applying its table-driven, parallel, and goleak-supported testing patterns in your Go projects.

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 Golang for better test clarity?

Table-driven tests in Golang use named subtests to ensure clarity and determinism. You define test cases in a struct slice and iterate over them, executing subtests with t.Run to isolate failures and maintain fast, readable test suites.

What is the best way to detect goroutine leaks in Go integration tests?

Goroutine leaks in Go integration tests are detected using goleak. You integrate goleak verification in TestMain to ensure tests do not leave lingering goroutines, guaranteeing deterministic and safe test suite execution.

How do I use testify mocks for Go unit testing?

Testify mocks for Go unit testing allow you to define expected method calls and return values on mock objects. This isolates dependencies and ensures fast, maintainable unit tests without relying on external services.

Does this approach support fuzzing and benchmarking in Go projects?

Yes, this approach supports fuzzing and benchmarking in Go projects. It specifies clear patterns for writing benchmarks and fuzzing tests to evaluate performance and uncover edge-case vulnerabilities, ensuring production-ready code.

Can I run parallel tests safely in Go without causing data races?

Yes, you can run parallel tests safely in Go by calling t.Parallel within subtests. Following structured parallel testing patterns ensures fast execution speeds while avoiding data races and maintaining test determinism.