Skip to content
Back to skills

Test Driven Development

ASecurity

Red-green-refactor TDD implementation cycle

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
ai-agentsgotestingrefactoring

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add PedroMosquera/squadai --skill test-driven-development --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Test Driven Development?

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

Security grade badge for Test Driven Development
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/pedromosquera-test-driven-development/badge)](https://www.skillsdirectory.com/skills/pedromosquera-test-driven-development)

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: test-driven-development
description: Red-green-refactor TDD implementation cycle
methodology: tdd
---

# Test-Driven Development Skill

Implement code using the red-green-refactor cycle. This skill is used by the
Implementer to write code driven by failing tests.

## Core Principle

Write the MINIMUM code to make a failing test pass. No more. Then refactor
to improve quality without changing behavior.

## Steps

### Phase 1: RED (write a failing test)

1. Pick the next test from the implementation plan.
2. Write the test code first, before any implementation.
3. Run the test: it MUST fail (red). If it passes without implementation, the
   test is not testing the right thing.
4. Read the failure message. It tells you exactly what to implement.

### Phase 2: GREEN (make the test pass)

1. Write the MINIMUM implementation to make the failing test pass.
   - No extra logic, no anticipated future use cases
   - Hardcoding is acceptable at this stage if it makes the test pass
   - Copy-paste is acceptable if it moves quickly to green
2. Run the test: it MUST pass (green).
3. Run ALL tests: ensure no regressions.
4. Do NOT refactor yet.

### Phase 3: REFACTOR (improve the code)

1. Only after tests are green, improve code quality.
   - Remove duplication
   - Improve naming
   - Extract helper functions
   - Simplify logic
2. Run tests after every change; refactoring must not break anything.
3. Do NOT add new behavior during refactoring.
4. When satisfied, move to the next test in the plan.

## Rules

- Never skip the red phase; always write the test first
- Never write more code than needed to pass the current test
- Never refactor while red; only refactor on green
- Commit after each green-refactor cycle (small, frequent commits)
- If a test is hard to write, it signals a design problem, so fix the design

## Test Structure

Follow table-driven tests for multiple scenarios:

```go
func TestFunctionName(t *testing.T) {
    tests := []struct {
        name    string
        input   InputType
        want    OutputType
        wantErr bool
    }{
        {name: "happy path", input: ..., want: ..., wantErr: false},
        {name: "empty input", input: ..., want: ..., wantErr: true},
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            got, err := FunctionName(tt.input)
            if (err != nil) != tt.wantErr {
                t.Errorf("unexpected error: %v", err)
            }
            if got != tt.want {
                t.Errorf("got %v, want %v", got, tt.want)
            }
        })
    }
}
```

## Output Format

For each RED-GREEN-REFACTOR cycle, produce:
1. The failing test code
2. The minimal implementation
3. Any refactoring applied
4. Confirmation that all tests pass

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…