2
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill 89jobrien/steve --skill golang-testing- SKILL.md9.7 KB
Overview
This skill delivers practical, battle-tested patterns for testing Go applications: table-driven tests, interface-based mocking, integration tests with containers, benchmarks, and test organization. It focuses on concrete examples and reusable patterns you can drop into your codebase to make tests expressive, fast, and maintainable.
How this skill works
The skill inspects common testing scenarios and provides idiomatic Go examples: table-driven unit tests with subtests, mock implementations for interfaces, Testify assertion patterns, Testcontainers-based integration tests, benchmark templates, and setup/teardown fixtures. Each pattern includes minimal, copyable code and guidance on where to apply it (unit vs integration vs performance).
When to use it
- Writing unit tests for functions and methods where inputs/outputs vary
- Creating table-driven tests to cover multiple cases and edge conditions
- Mocking dependencies by implementing interfaces for isolation
- Running integration tests that require databases or external services
- Measuring performance with benchmarks and parallel benchmarks
- Organizing tests, fixtures, and build tags for clarity and speed
Best practices
- Test behavior, not implementation: assert outcomes, not internals
- Keep tests focused: aim for one assertion intent per subtest
- Use t.Helper() in helpers and t.Run for descriptive subtests
- Use t.Parallel() for independent tests to speed execution
- Skip slow integration tests with testing.Short() and use build tags
- Avoid shared state: each test should setup and teardown its own fixtures
Example use cases
- Table-driven tests for arithmetic, parsing, or validation logic
- Mocking a repository or external API using small mock structs
- Integration test that spins up a PostgreSQL container, runs migrations, and verifies repository behavior
- Benchmarks to compare algorithm implementations and input sizes
- HTTP handler tests using httptest with mock services for success and error flows
FAQ
Use mocks for fast, deterministic unit tests. Use Testcontainers when you need to validate real integrations, migrations, or driver-specific behavior that mocks cannot reproduce.
How do I keep integration tests from slowing CI?
Mark them with build tags or skip them in short mode (testing.Short()). Run integration suites separately or in a dedicated pipeline stage.