Agent skill
go-testing-subtests
Subtest patterns with t.Run
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/testing/go-testing-subtests
SKILL.md
Subtests with t.Run
Use t.Run to group related tests and enable selective execution.
CORRECT
func Test_User_Validation(t *testing.T) {
t.Run("valid email", func(t *testing.T) {
user := User{Email: "[email protected]"}
if err := user.Validate(); err != nil {
t.Errorf("expected valid, got error: %v", err)
}
})
t.Run("invalid email", func(t *testing.T) {
user := User{Email: "invalid"}
if err := user.Validate(); err == nil {
t.Error("expected error, got nil")
}
})
t.Run("empty email", func(t *testing.T) {
user := User{Email: ""}
if err := user.Validate(); err == nil {
t.Error("expected error, got nil")
}
})
}
Run specific subtest:
go test -run Test_User_Validation/invalid_email
Why:
- Logical grouping of related tests
- Can run subtests individually
- Clean test output with hierarchy
- Failures don't stop other subtests
WRONG
func Test_User_ValidEmail(t *testing.T) { /* ... */ }
func Test_User_InvalidEmail(t *testing.T) { /* ... */ }
func Test_User_EmptyEmail(t *testing.T) { /* ... */ }
Problems:
- No grouping relationship
- Harder to run related tests together
- More verbose test names
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?