# TDD Mastery

Test-driven development workflow with Red-Green-Refactor cycle across languages

- Repository: https://github.com/rohitg00/awesome-claude-code-toolkit (2800 stars)
- Category: Testing
- License: Apache-2.0
- Last updated: 2026-05-12
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add rohitg00/awesome-claude-code-toolkit --skill tdd-mastery -g -a claude-code -y`
Codex: `npx skills add rohitg00/awesome-claude-code-toolkit --skill tdd-mastery -g -a codex -y`
Cursor: `npx skills add rohitg00/awesome-claude-code-toolkit --skill tdd-mastery -g -a cursor -y`
Gemini CLI: `npx skills add rohitg00/awesome-claude-code-toolkit --skill tdd-mastery -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add rohitg00/awesome-claude-code-toolkit`

## Description

Test-driven development workflow with Red-Green-Refactor cycle across languages

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# TDD Mastery

## Core Cycle: Red-Green-Refactor

1. **Red** - Write a failing test that defines the desired behavior
2. **Green** - Write the minimum code to make the test pass
3. **Refactor** - Clean up while keeping tests green

Never write production code without a failing test first. Each cycle should take 2-10 minutes.

## Test Structure

Use the Arrange-Act-Assert pattern consistently:

```
Arrange: Set up test data and dependencies
Act:     Execute the behavior under test
Assert:  Verify the expected outcome
```

Name tests as `test_<unit>_<scenario>_<expected_result>` or `it("should <behavior> when <condition>")`.

## Jest / Vitest Patterns

```typescript
describe("OrderService", () => {
  it("should apply discount when order exceeds threshold", () => {
    const order = createOrder({ items: [{ price: 150, qty: 1 }] });
    const result = applyDiscount(order, { threshold: 100, percent: 10 });
    expect(result.total).toBe(135);
  });

  it("should throw when applying discount to empty order", () => {
    const order = createOrder({ items: [] });
    expect(() => applyDiscount(order, defaultDiscount)).toThrow(EmptyOrderError);
  });
});
```

Use `vi.fn()` / `jest.fn()` for mocks. Prefer dependency injection over module mocking. Use `beforeEach` for shared setup, never share mutable state between tests.

## pytest Patterns

```python
@pytest.fixture
def db_session():
    session = create_test_session()
    yield session
    session.rollback()

def test_create_user_stores_hashed_password(db_session):
    user = UserService(db_session).create(email="a@b.com", password="secret")
    assert user.password_hash != "secret"
    assert verify_password("secret", user.password_hash)

@pytest.mark.parametrize("input,expected", [
    ("", False),
    ("short", False),
    ("ValidPass1!", True),
])
def test_password_validation(input, expected):
    assert validate_password(input) == expected
```

The rest: https://github.com/rohitg00/awesome-claude-code-toolkit/blob/HEAD/skills/tdd-mastery/SKILL.md
