writing-go-tests
Applies current Go testing best practices, including concurrent testing, mocking, and table-driven design for robust software development.
Introduction
This skill serves as a comprehensive guide for implementing high-quality unit, integration, and performance tests within Go codebases. It is designed for software engineers who seek to maintain reliable, maintainable, and testable code by strictly following modern Go testing standards and idioms. By applying these guidelines, developers can effectively reduce regression risks, improve coverage metrics, and ensure their systems perform correctly under concurrent load. The skill provides clear strategies for handling complex dependencies, improving test execution speed, and managing fixtures or cleanup tasks.
- Key capabilities include guidance on table-driven testing using map-based structures for better failure output readability.
- Implementation of Go 1.24+ features such as testing/synctest for deterministic concurrency testing to eliminate flaky tests.
- Practical advice on mocking and test doubles, prioritizing integration tests with real dependencies like Testcontainers over complex generated mocks.
- Best practices for coverage targets, aiming for a pragmatic 70-80% threshold rather than focusing solely on absolute numbers.
- Specific guidance on organization, using internal tests for unexported logic and external packages for API integration testing.
- Techniques for resource cleanup, preferring t.Cleanup() over traditional defer statements for cleaner test lifecycle management.
When using this skill, expect the agent to recommend tools like google/go-cmp for deep equality checks and testify for richer assertions when the standard library is insufficient. It helps refine benchmark suites by suggesting the B.Loop() pattern and usage of benchstat for statistical validation. Users should be aware that this skill emphasizes behavior-driven testing over implementation details, focusing on pragmatic excellence. It is primarily used during refactoring, new feature development, or when diagnosing test suite performance issues. The skill helps identify the optimal approach for complex scenarios like golden file testing or handling environment-specific configurations without relying on rigid build tags.
Repository Stats
- Stars
- 2
- Forks
- 0
- Open Issues
- 0
- Language
- Go
- Default Branch
- main
- Sync Status
- Idle
- Last Synced
- May 3, 2026, 05:55 PM