tdd-test-writer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TDD Test Writer

TDD测试编写器

Use this skill to complete the RED phase of TDD: define behavior with tests first, verify they fail for the right reason, then hand off implementation with objective pass criteria.
使用本技能完成TDD的红色阶段:优先通过测试定义行为,验证测试因正确原因失败,随后交付带有客观通过标准的实现任务。

When To Use

适用场景

Use this skill when the user asks for:
  • test-first development
  • TDD / RED-GREEN-REFACTOR workflow
  • writing tests that implementation agents must satisfy
  • bugfixes that need regression tests before code changes
当用户有以下需求时使用本技能:
  • 测试先行开发
  • TDD / 红-绿-重构工作流
  • 编写实现Agent必须满足的测试
  • 代码变更前需要编写回归测试的bug修复任务

Required Rules

强制规则

  1. Do not modify production code while running this skill.
  2. Use subagent role
    tdd_test_writer
    for RED-phase test authoring whenever available.
  3. Write behavior-focused tests, not placeholders.
  4. Every new/updated test must fail before handoff.
  5. Failures must come from missing or incorrect production behavior, not broken tests.
  6. Prefer deterministic, targeted test commands over full-suite runs when possible.
  7. For bugfix tasks, add a regression test that captures the reported failure mode.
  1. 运行本技能时请勿修改生产代码。
  2. 只要可用,就使用子Agent角色
    tdd_test_writer
    完成红色阶段的测试编写工作。
  3. 编写聚焦行为的测试,而非占位符。
  4. 所有新增/更新的测试在交付前必须处于失败状态。
  5. 失败必须源于生产行为缺失或不正确,而非测试本身存在问题。
  6. 尽可能使用确定性的、针对性的测试命令,而非运行全量测试套件。
  7. 对于bug修复任务,新增回归测试来复现上报的失败模式。

Workflow

工作流程

1. Define Behavior Contract

1. 定义行为契约

  • Convert user request into explicit acceptance criteria.
  • Identify happy path, edge cases, and negative-path expectations.
  • If requirements are ambiguous, record
    ASSUMPTION:
    lines in output.
  • 将用户需求转换为明确的验收标准。
  • 识别正常路径、边界场景和异常路径的预期结果。
  • 如果需求存在歧义,在输出中记录
    ASSUMPTION:
    行说明假设内容。

2. Delegate Test Authoring To
tdd_test_writer

2. 委派测试编写任务给
tdd_test_writer

  • Spawn a
    tdd_test_writer
    subagent with task scope, target files, and acceptance criteria.
  • Require the subagent to write/update tests only (no production code changes).
  • Require command output proving RED-state failure for the new tests.
  • If
    tdd_test_writer
    is unavailable, continue directly and note
    FALLBACK: tdd_test_writer unavailable
    .
  • 生成
    tdd_test_writer
    子Agent,提供任务范围、目标文件和验收标准。
  • 要求子Agent仅编写/更新测试(不得修改生产代码)。
  • 要求子Agent提供命令输出,证明新增测试处于红色失败状态。
  • 如果无法使用
    tdd_test_writer
    ,直接继续后续流程并备注
    FALLBACK: tdd_test_writer unavailable

3. Discover Existing Test Conventions

3. 对齐现有测试规范

  • Detect framework and runner from the repo (for example
    vitest
    ,
    jest
    ,
    pytest
    ,
    go test
    ,
    cargo test
    ).
  • Follow existing directory, naming, and fixture conventions.
  • Reuse existing helpers instead of introducing duplicate test utilities.
  • 从代码库中检测使用的测试框架和运行器(例如
    vitest
    jest
    pytest
    go test
    cargo test
    )。
  • 遵循现有的目录、命名和测试夹具规范。
  • 复用现有辅助工具,不要引入重复的测试工具函数。

4. Author RED-Phase Tests

4. 编写红色阶段测试

  • Create or update test files that encode the behavior contract.
  • Keep tests small and intention-revealing (clear names and assertions).
  • Include at least one negative-path assertion where applicable.
  • Avoid network/time randomness; mock or fixture external systems.
  • 创建或更新测试文件,编码实现行为契约。
  • 保持测试精简且意图清晰(命名和断言明确)。
  • 适用场景下至少包含一个异常路径的断言。
  • 避免网络/时间随机性;对外部系统进行mock或使用测试夹具。

5. Verify RED State

5. 验证红色状态

  • Run the narrowest command that executes the new tests.
  • Confirm they fail for the expected behavioral gap.
  • If failure is caused by test syntax/setup, fix tests and rerun.
  • 运行执行新增测试所需的最小范围命令。
  • 确认测试因预期的行为缺口失败。
  • 如果失败是由测试语法/配置导致,修复测试后重新运行。

6. Produce Implementation Handoff

6. 生成实现交付物

Return a block that implementation agents must follow. The handoff must include:
  • subagent used (
    tdd_test_writer
    ) or explicit fallback reason
  • exact test files created/updated
  • exact verification command(s)
  • short failure summary proving RED state
  • immutable test constraint (do not edit tests unless requirement changes)
  • pass criteria that define task completion
返回一个实现Agent必须遵循的代码块。交付物必须包含:
  • 所用的子Agent(
    tdd_test_writer
    )或明确的降级原因
  • 新增/更新的具体测试文件路径
  • 具体的验证命令
  • 证明红色状态的简短失败摘要
  • 不可变的测试约束(除非需求变更,否则不得修改测试)
  • 定义任务完成的通过标准

Required Output Format

要求输出格式

markdown
TDD RED PHASE COMPLETE
markdown
TDD RED PHASE COMPLETE

Authoring Mode

Authoring Mode

  • Subagent: tdd_test_writer
  • Fallback: [only if subagent unavailable]
  • Subagent: tdd_test_writer
  • Fallback: [only if subagent unavailable]

Test Files

Test Files

  • [path]
  • [path]

Verification

Verification

  • Command: [exact command]
  • Result: FAIL (expected)
  • Failure reason: [1-2 lines tied to missing behavior]
  • Command: [exact command]
  • Result: FAIL (expected)
  • Failure reason: [1-2 lines tied to missing behavior]

Implementation Contract (for next agent)

Implementation Contract (for next agent)

  1. Do not modify these tests: [paths]
  2. Implement production changes only in: [paths or modules]
  3. Completion gate: [exact command] passes with no test weakening.
  4. Run broader safety check: [secondary command]
  5. Return evidence: changed files + command output summary.
  1. Do not modify these tests: [paths]
  2. Implement production changes only in: [paths or modules]
  3. Completion gate: [exact command] passes with no test weakening.
  4. Run broader safety check: [secondary command]
  5. Return evidence: changed files + command output summary.

Assumptions

Assumptions

  • ASSUMPTION: [only if needed]
undefined
  • ASSUMPTION: [only if needed]
undefined

Quality Bar

质量标准

  • Tests fail before implementation and are reproducible locally.
  • Assertions are specific enough to prevent false positives.
  • Regression coverage is present for bugfix-driven tasks.
  • Handoff is precise enough that another agent can execute without clarifications.
  • 测试在实现完成前处于失败状态,且本地可复现。
  • 断言足够精准,可避免误报。
  • 对于bug修复驱动的任务,包含回归测试覆盖。
  • 交付内容足够精准,其他Agent无需额外澄清即可执行。