Skip to content
Back to skills

Subtests

ASecurity

Subtest patterns with t.Run

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added February 7, 2026
testinggobashtesting

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add JamesPrial/claudefiles --skill subtests --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Subtests?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Subtests
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jamesprial-subtests/badge)](https://www.skillsdirectory.com/skills/jamesprial-subtests)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: go-testing-subtests
description: Subtest patterns with t.Run
---

# Subtests with t.Run

Use t.Run to group related tests and enable selective execution.

## CORRECT

```go
func Test_User_Validation(t *testing.T) {
    t.Run("valid email", func(t *testing.T) {
        user := User{Email: "test@example.com"}
        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:**
```bash
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

```go
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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.