Skip to content
Back to skills

Table

ASecurity

Table-driven test patterns for Go

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

Security analysis

A100/100

Scanned February 12, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Table?

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

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

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-table
description: Table-driven test patterns for Go
---

# Table-Driven Tests

Use when you have 2+ test cases for the same function.

## CORRECT

```go
func Test_Add_Cases(t *testing.T) {
    tests := []struct {
        name string
        a    int
        b    int
        want int
    }{
        {name: "positive numbers", a: 2, b: 3, want: 5},
        {name: "negative numbers", a: -1, b: -2, want: -3},
        {name: "zero", a: 0, b: 0, want: 0},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got := Add(tt.a, tt.b)
            if got != tt.want {
                t.Errorf("Add(%d, %d) = %d, want %d", tt.a, tt.b, got, tt.want)
            }
        })
    }
}
```

**Why:**
- Single loop handles all cases
- Easy to add new cases
- Named cases for clear failure messages
- Each case runs as subtest

## WRONG

```go
func Test_Add(t *testing.T) {
    if Add(2, 3) != 5 {
        t.Error("2 + 3 failed")
    }
    if Add(-1, -2) != -3 {
        t.Error("-1 + -2 failed")
    }
    if Add(0, 0) != 0 {
        t.Error("0 + 0 failed")
    }
}
```

**Problems:**
- Repetitive code
- First failure stops remaining tests
- Hard to add new cases
- No case names in output

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.