jnmetacode avatar

Test Driven Development

This is TDD enforcement as a system prompt. It locks Claude into red-green-refactor with zero tolerance for shortcuts. Write a failing test first, watch it fail for the right reason, then write minimal code to pass it. The real teeth are in the rules: if you write implementation before tests, you delete it and start over, no exceptions. It catches the usual escape hatches like "I'll add tests after" or "I already manually tested it" and explains why they break the discipline. Includes a verification checklist, common excuses with rebuttals, and integration with anti-pattern docs. Useful if you want Claude to be strict about process, not just suggest best practices.

skills.sh installs
1.1K
GitHub stars
8.5K
last updated
Aug 21, 2026

Install

$ npx -y skills add jnmetacode/superpowers-zh --skill test-driven-development --agent claude-code

Installs into .claude/skills of the current project.

Files

测试驱动开发(TDD)

概述

先写测试。看它失败。写最少的代码让它通过。

核心原则: 如果你没有看到测试失败,你就不知道它是否测试了正确的东西。

违反规则的字面意思就是违反规则的精神。

何时使用

始终使用:

  • 新功能
  • Bug 修复
  • 重构
  • 行为变更

例外(需询问你的人类伙伴):

  • 一次性原型
  • 生成的代码
  • 配置文件

想着"就这一次跳过 TDD"?停下来。那是在给自己找借口。

铁律

没有失败的测试,就不写生产代码

先写了代码再写测试?删掉它。从头来过。

没有例外:

  • 不要保留作为"参考"
  • 不要在写测试时"改编"它
  • 不要看它
  • 删除就是删除

从测试出发,重新实现。句号。

红-绿-重构

digraph tdd_cycle {
    rankdir=LR;
    red [label="红灯\n编写失败的测试", shape=box, style=filled, fillcolor="#ffcccc"];
    verify_red [label="验证正确失败", shape=diamond];
    green [label="绿灯\n最少代码", shape=box, style=filled, fillcolor="#ccffcc"];
    verify_green [label="验证通过\n全部绿灯", shape=diamond];
    refactor [label="重构\n清理代码", shape=box, style=filled, fillcolor="#ccccff"];
    next [label="下一个", shape=ellipse];

    red -> verify_red;
    verify_red -> green [label="是"];
    verify_red -> red [label="错误的\n失败"];
    green -> verify_green;
    verify_green -> refactor [label="是"];
    verify_green -> green [label="否"];
    refactor -> verify_green [label="保持\n绿灯"];
    verify_green -> next;
    next -> red;
}

红灯 - 编写失败的测试

写一个最小的测试来展示期望行为。

Sponsors

Details

Repository
github.com/jnmetacode/superpowers-zh
Categories
Testing & QA, Debugging
First seen
Jun 3, 2026

More from jnmetacode/superpowers-zh

All 20
1microsoft avatarfile-test-bugmicrosoft/azure-skillsfile test bug924skills.sh installs
2mindrally avatartestingmindrally/skillsGeneral testing best practices and guidelines for writing comprehensive, maintainable tests across different testing frameworks and languages.861skills.sh installs
3google-labs-code avatartdd-red-green-refactorgoogle-labs-code/design.mdEnforces a disciplined Red-Green-Refactor (TDD) workflow in TypeScript/Node.js. Use this whenever creating new features, fixing bugs, or migrating logic to ensu732skills.sh installs
4theqtcompanyrnd avatarqt-qml-testtheqtcompanyrnd/agent-skills>-689skills.sh installs
5proffesor-for-testing avatarcompatibility-testingproffesor-for-testing/agentic-qeCross-browser, cross-platform, and cross-device compatibility testing ensuring consistent experience across environments. Use when validating browser support, t654skills.sh installs
6alirezarezvani avatarab-test-setupalirezarezvani/claude-skillsWhen the user wants to plan, design, or implement an A/B test or experiment. Also use when the user mentions "A/B test," "split test," "experiment," "test this 636skills.sh installs