golang-testing

Write table-driven Go tests with named subtests and goleak detection.

Updated Oct 1, 2024
One-click install
npx skills add https://github.com/mrlorentx/.files --skill golang-testing-mrlorentx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/mrlorentx/.files/tree/main/ai/claude/skills/golang-testing
Command: npx skills add https://github.com/mrlorentx/.files --skill golang-testing-mrlorentx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go developers often struggle to write fast, reliable tests that verify observable behavior rather than implementation details.

Core Features & Use Cases

  • Table-driven tests with named subtests to improve readability and parallelism.
  • Integration testing patterns using build tags, mocking, and example-based documentation to align with CI.
  • Guidance on reducing flakiness, employing goleak for goroutine leak detection, and practical Go testing patterns.

Quick Start

Follow these patterns to scaffold and run Go tests quickly with correct structure.

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

To write table-driven tests, define a slice of test case structs and loop through them using t.Run to execute named subtests. This pattern improves test readability, isolates failures, and allows running cases in parallel.

How do I detect goroutine leaks in my Go tests?

Detect goroutine leaks in Go tests by integrating goleak to verify all background goroutines terminate cleanly. This reduces test flakiness and ensures observable behavior across integration tests.

What is the best way to structure Go integration tests using build tags?

Structure Go integration tests using build tags to isolate slow tests from fast unit tests. This separation aligns with CI workflows and keeps local development fast by excluding integration suites by default.

How do I use testify mocks to avoid testing implementation details in Go?

Use testify mocks to simulate external dependencies and verify observable behavior rather than internal implementation details. This approach produces deterministic tests that remain robust during refactoring.

Can I use example functions for documentation in go-testing?

Yes, you can use example functions in go-testing to compile executable documentation. These examples verify output correctness during CI and automatically generate reference snippets in Go package documentation.