go-testing
Go testing patterns. Routes to specific patterns.
When & Why to Use This Skill
This Claude skill provides a comprehensive collection of idiomatic Go testing patterns and best practices. It streamlines the creation of robust test suites by offering standardized templates for table-driven tests, subtests, benchmarks, and helper functions, ensuring high code quality and maintainability in Golang projects.
Use Cases
- Implementing table-driven tests to efficiently validate multiple input-output scenarios within a single test function.
- Organizing complex test logic into hierarchical subtests using t.Run for improved readability and targeted execution.
- Creating reusable test helper functions that leverage t.Helper() to provide accurate error reporting and cleaner test code.
- Benchmarking Go code performance using standard library patterns to identify and resolve bottlenecks.
- Ensuring Go testing best practices, such as proper naming conventions and safe parallel test execution.
| name | go-testing |
|---|---|
| description | Go testing patterns. Routes to specific patterns. |
Testing
Route by Pattern
- Table-driven tests → see table/
- Subtests with t.Run → see subtests/
- Test helpers → see helpers/
- Benchmarks → see benchmarks/
Quick Check
- Tests named Test_Function_Scenario
- Table tests for >2 cases
- Helpers call t.Helper()
- Parallel tests capture loop vars
Common Patterns
Basic test structure:
func Test_Function_Scenario(t *testing.T) {
// Arrange
input := "test"
// Act
result := Function(input)
// Assert
if result != expected {
t.Errorf("got %v, want %v", result, expected)
}
}