Skip to content
Back to skills

test-driven-development

ASecurity

Enforces TDD discipline with RED-GREEN-REFACTOR cycle. Use when writing new features, fixing bugs, or refactoring code. Ensures tests genuinely verify behavior.

  • 286 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added June 5, 2026
ai-agentsgobashtestingrefactoringgit

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned June 5, 2026

npx -y skills add majiayu000/spellbook --skill skills --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/majiayu000-test-driven-development/badge)](https://www.skillsdirectory.com/skills/majiayu000-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: Enforces TDD discipline with RED-GREEN-REFACTOR cycle. Use when writing new features, fixing bugs, or refactoring code. Ensures tests genuinely verify behavior.
---
# Test-Driven Development (TDD)

> From [obra/superpowers](https://github.com/obra/superpowers)

## Core Principle

Write tests before implementation. Watch them fail. Write minimal code to pass.

**THE IRON LAW: NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST**

## When to Apply TDD

- New features
- Bug fixes
- Refactoring
- Any behavior changes

## The Red-Green-Refactor Cycle

### RED: Write a Failing Test

1. Write ONE minimal test demonstrating desired behavior
2. Use clear, descriptive test names
3. Use real code, avoid unnecessary mocks
4. Test should fail for the RIGHT reason

```
# Verify RED
- Run the test
- Confirm it fails
- Confirm failure is NOT due to syntax errors
- Confirm you're not testing existing functionality
```

### GREEN: Make It Pass

1. Write the SIMPLEST code that makes the test pass
2. Don't add extra features
3. Don't optimize yet
4. Just make it work

```
# Verify GREEN
- Run all tests
- Confirm new test passes
- Confirm no other tests broke
```

### REFACTOR: Clean Up

1. Improve code quality while keeping tests green
2. Remove duplication
3. Improve naming
4. Extract helpers if needed
5. Run tests after each change

## Why This Order Matters

Tests written AFTER implementation:
- Pass immediately (proves nothing)
- You never see them fail
- Cannot verify they test what matters
- Manual testing is NOT a substitute

## Common Rationalizations to REJECT

| Excuse | Reality |
|--------|---------|
| "Too simple to test" | Simple code still breaks |
| "I'll write tests after" | Post-implementation tests pass immediately |
| "Already manually tested" | Manual testing lacks systematic rigor |
| "Deleting work is wasteful" | Unverified code is technical debt |
| "Keep as reference" | You'll adapt it; that's testing-after |

## Red Flags Requiring RESTART

If any of these occur, DELETE the code and start over:

- Writing code before tests
- Tests passing immediately on first run
- Rationalizing "just this once"
- Planning to "test later"
- Keeping pre-written code "as reference"

## Example Workflow

```bash
# 1. RED - Write failing test
def test_user_can_login_with_valid_credentials():
    user = create_user(email="test@example.com", password="secret")
    result = login(email="test@example.com", password="secret")
    assert result.success == True
    assert result.user == user

# 2. Run test - MUST FAIL
# 3. GREEN - Implement minimal code
def login(email, password):
    user = User.find_by_email(email)
    if user and user.check_password(password):
        return LoginResult(success=True, user=user)
    return LoginResult(success=False, user=None)

# 4. Run test - MUST PASS
# 5. REFACTOR - Clean up if needed
```

## Summary

1. Write test first
2. Watch it fail
3. Write minimal code to pass
4. Refactor while green
5. Repeat

Files in this skill

  • api-design/SKILL.md8.1 KB
  • api-design/reference/comparison.md6.1 KB
  • api-design/reference/graphql.md6.2 KB
  • api-design/reference/grpc.md7.4 KB
  • api-design/reference/rest.md5.3 KB
  • api-design/templates/graphql/schema.graphql4.5 KB
  • api-design/templates/grpc/service.proto6 KB
  • api-design/templates/openapi/openapi.yaml8.3 KB
  • app-ui-design/SKILL.md11.5 KB
  • app-ui-design/reference/accessibility.md12.8 KB
  • app-ui-design/reference/color-theory.md11.7 KB
  • app-ui-design/reference/extended.md7.9 KB
  • app-ui-design/reference/ios-guidelines.md8.6 KB
  • app-ui-design/reference/material-design.md13.8 KB
  • app-ui-design/templates/design-system-template.md8.8 KB
  • ask-opencli/SKILL.md7.7 KB
  • auth-security/SKILL.md10.7 KB
  • auth-security/reference/attacks.md7.8 KB
  • auth-security/reference/jwt.md8 KB
  • auth-security/reference/oauth2.1.md8.6 KB

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.