Command Palette

Search for a command to run...

Назад к скиллам
скилл № 01771

tdd-workflow

Red-Green-Refactor cycle for test-first development. Write failing test, implement minimal code, refactor safely. Use when developing new features or fixing…

БесплатноБез исполняемых скриптов
sethdfordот sethdford★ 51 звезда на GitHub

Установить tdd-workflow в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

TDD Workflow

Disciplined test-first development with the Red-Green-Refactor cycle. Tests shape API design; fearless refactoring becomes possible.

Context

You are guiding the engineer through TDD. Your role is to help them:

  • Write clear, focused tests that describe desired behavior before implementation
  • Implement minimal code that passes the test (no over-engineering)
  • Refactor with confidence, knowing tests will catch mistakes
  • Keep cycles short (5-15 minutes) to maintain momentum
  • Use test failures as design feedback

TDD is not just about testing; it's about using tests as a design tool to improve code clarity and maintainability.

Domain Context

Based on Kent Beck, Bob Martin, and J.B. Rainsberger:

  • Red Phase: Write test describing desired behavior; it fails because feature doesn't exist. This failure is essential—it proves the test actually tests something.
  • Green Phase: Write minimal code to pass the test. "Minimal" means: just enough logic; no premature optimization; no extra features.
  • Refactor Phase: Improve code without changing behavior. Extract methods, improve names, reduce duplication. Tests protect against regressions.
  • Design Feedback: If tests are hard to write, the API is hard to use. If mocking is complex, coupling is too tight. Tests reveal design problems early.
  • Regression Safety: Previous tests continue passing, so refactoring is fearless. This enables continuous improvement.
  • Cycle Length: 5-15 minutes per cycle. Longer cycles indicate the test is too complex; break it down.

When to Use This Skill

  • Starting a new feature where behavior is well-defined
  • Fixing a bug (write test for the bug first, then implement fix)
  • Adding to a codebase already using TDD (maintain consistency)
  • When you want to confidently refactor without fear of regressions
  • When API design is uncertain (tests force clarity)

Prerequisites

Before starting TDD, confirm:

  • Clear Requirements: Understand what "done" looks like for this feature
  • Test Framework: Know how to write tests in your language (unittest, pytest, Jest, xUnit)
  • Development Environment: Can run tests locally in <5 seconds
  • Existing Tests: Review existing tests to match style and patterns
  • Integration Plan: Where will this code plug into the system?

Instructions (Detailed)

1. Understand the Feature

Read requirements carefully. Ask clarifying questions:

  • What is the input? What is the expected output?
  • What are edge cases or error conditions?
  • How does this interact with existing code?
  • What business value does this provide?

Write down the acceptance criteria. These become test cases.

2. Write the First Failing Test (Red)

Write a single test that describes one piece of desired behavior. Make it fail.

Example (Python):

def test_user_email_validation_rejects_missing_at_symbol():
    # Arrange
    validator = EmailValidator()
    # Act
    is_valid = validator.is_valid("userexample.com")
    # Assert
    assert is_valid is False

Rules for this phase:

  • One assertion per test (or tightly related assertions)
  • Clear name: test_<subject>_<condition>_<expected_outcome>
  • Test behavior, not implementation: Don't test private methods; test observable behavior
  • Arrange-Act-Assert: Set up state, call code, verify outcome
  • Make it fail first: Run the test; confirm it fails with the error you expect

3. Implement Minimal Code (Green)

Write the simplest code that passes the test. No optimization, no extra features.

Example (Python):

class EmailValidator:
    def is_valid(self, email: str) -> bool:
        return "@" in email

This is deliberately naive. It passes the test. Now the test can guide the next iteration.

Rules for this phase:

  • No premature optimization: Avoid performance tweaks; optimize when profiling shows a problem
  • No extra features: Implement only what the test requires
  • Copy-paste is acceptable: Duplication is fixed in Refactor phase
  • Comment if unclear: If you needed to think hard, add a comment for future readers

4. Verify the Test Passes (Green)

Run the test. It should pass.

python -m pytest test_email_validator.py::test_user_email_validation_rejects_missing_at_symbol -v

If it fails, debug the implementation, not the test. The test defines correctness.

5. Check Existing Tests Still Pass

Run the full test suite. No regressions.

python -m pytest tests/

If an existing test breaks, you've changed behavior unintentionally. Fix the implementation.

6. Refactor (Refactor)

Now improve the code: better names, extract methods, reduce duplication. Tests protect you.

Example: The naive implementation passes one test. Write the next test for a positive case:

def test_user_email_validation_accepts_valid_email():
    validator = EmailValidator()
    assert validator.is_valid("user@exampl
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

  1. 01Read
  2. 02Grep
  3. 03Glob
  4. 04Write
  5. 05Edit
  6. 06Bash

Вложенные файлы

  • examples/example-output.md
  • template.md

FAQ

Что делает скилл tdd-workflow?

Red-Green-Refactor cycle for test-first development. Write failing test, implement minimal code, refactor safely. Use when developing new features or fixing bugs in test-driven projects.

Как установить скилл tdd-workflow?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл tdd-workflow запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить tdd-workflow с