AgentSkillsCN

tdd-workflow

严格执行测试驱动开发原则:RED(编写失败的测试)→ GREEN(编写最小化代码以通过测试)→ REFACTOR(清理代码)。绝不例外。

SKILL.md
--- frontmatter
name: tdd-workflow
description: Enforces strict Test-Driven Development. RED (write failing test) → GREEN (minimum code to pass) → REFACTOR (clean up). No exceptions.
user-invocable: false

TDD Workflow

When This Skill Activates

  • When writing any new functionality
  • When modifying existing behavior
  • When fixing bugs (write the reproduction test first)

This is a background skill. It should be internalized and applied automatically during all implementation work.

The Cycle: RED → GREEN → REFACTOR

RED — Write a Failing Test First

  1. Write a test that describes the DESIRED behavior.
  2. Run it. It MUST fail.
  3. If it passes, either:
    • The feature already exists (verify and skip)
    • The test is wrong (fix the test)
  4. The failing test is your specification. It defines "done."

GREEN — Write Minimum Code to Pass

  1. Write the simplest, ugliest code that makes the test pass.
  2. Do NOT add extra features, abstractions, or polish.
  3. Do NOT handle edge cases that aren't tested yet.
  4. Run the test. It MUST pass.
  5. Run ALL tests. None may have broken.

REFACTOR — Clean Up

  1. Now improve the code: remove duplication, improve naming, simplify logic.
  2. After each change, run ALL tests. They must all still pass.
  3. If a test breaks during refactoring, undo the last change.
  4. This is NOT the time to add features.

Anti-Patterns (Do NOT Do These)

  • Writing implementation first, tests after → Tests become afterthoughts
  • Writing all tests up front → Too rigid, doesn't adapt to discoveries
  • Skipping RED phase → "It should work" is not TDD
  • Making tests pass by changing test expectations → Defeats the purpose
  • Adding features during REFACTOR → Scope creep

Test Quality Guidelines

  • Test BEHAVIOR, not implementation details
  • Each test should test ONE thing
  • Test names should read as specifications: should return 404 when user not found
  • Tests must be independent — no shared mutable state
  • Tests must be fast — mock external dependencies