AgentSkillsCN

tdd

采用红-绿-重构循环进行测试驱动开发。适用于用户希望通过 TDD 构建功能或修复缺陷时使用,或提及“红-绿-重构”、希望先写测试再进行开发,或要求采用 TDD 工作流程时使用。

SKILL.md
--- frontmatter
name: tdd
description: Test-driven development with red-green-refactor loop. Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants test-first development, or requests TDD workflow.

Test-Driven Development

Philosophy

Tests verify behavior through public interfaces, not implementation. Good tests survive refactors.

See principles.md for testing philosophy and anti-patterns.

Workflow

1. Planning

  • Confirm interface design with user
  • List behaviors to test (prioritize critical paths)
  • Get approval before writing code

2. Tracer Bullet

code
RED:   Write first test → fails
GREEN: Minimal code to pass → passes

3. Incremental Loop

For each remaining behavior:

code
RED:   Write next test → fails
GREEN: Minimal code to pass → passes

Rules:

  • One test at a time
  • Minimal code to pass
  • No refactoring while RED

4. Refactor

Once all tests GREEN:

  • Remove duplication
  • Improve structure
  • Tests must stay GREEN

Anti-Pattern: Horizontal Slices

DO NOT write all tests first, then all implementation. DO use vertical slices: one test → one implementation → repeat.

See examples.md for workflow demonstrations.