跳到主要内容
知仓学习社ZHICANG

tdd

Test-Driven Development enforcer. Red→Green→Refactor cycle with no production code without a failing test first. Use for new features and bug fixes.

不碰外部(只输出文字)无严重或高危命中hashgraph-online/awesome-codex-plugins

它会碰到什么

扫了多少1 个文本文件,4 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

TDD — Test-Driven Development

Iron Law

NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST. Violating the letter of this process is violating the spirit of this process.

Process

Red → Green → Refactor

  1. Red: Write a failing test that describes the desired behavior
  • Test name should read like a spec: it("returns 401 when token is expired") (reason: the test name IS your specification — it must communicate intent to future readers)
  • Run the test — confirm it fails for the right reason (reason: a test that fails for the wrong reason gives false confidence)
  1. Green: Write the minimum code to make the test pass
  • Do not write more than needed — because premature optimization is the root of all evil; make it work first
  • Do not optimize yet — because optimization without a passing test is speculation, not engineering
  • Run the test — confirm it passes (reason: a passing test is the only proof the code works)
  1. Refactor: Clean up without changing behavior
  • Extract duplicates, rename for clarity, simplify — because readability matters more than cleverness
  • Run tests again — must still pass (reason: refactoring without re-running tests is just renaming bugs)

Cycle

Repeat for each behavior. One test, one behavior, one cycle — because scope creep in a single test cycle leads to unverified code.

When to Trigger

  • /go subagents: always — because autonomous agents without TDD produce unverified code
  • New function or method being written
  • Bug fix (write regression test first — because a bug that happened once will happen again without a guard)

Anti-Rationalization

| Excuse | Rebuttal | What to do instead |

|--------|----------|--------------------|

| "This is too simple for tests" | Simple code still breaks. The Beyonce Rule applies: if you liked it, you should have put a test on it. | Write the test anyway — it takes 30 seconds and catches edge cases. |

| "I'll write tests after" | That's documentation, not specification. Tests written after confirm what you built; tests written before define what you should build. | Write the test first. If you can't describe the behavior, you don't understand the requirement. |

| "Tests slow me down" | 15 minutes of TDD saves hours of debugging regression bugs later. | Time the cycle — Red-Green-Refactor is usually faster than debug-after-deploy. |

| "I'll just test manually" | Manual tests don't catch regressions. Automate it once, save hours forever. | Write an automated test that runs on every commit. |

| "The types guarantee correctness" | Types check shape, not logic. add(a,b) can still return a-b. | Write a test that verifies the actual business rule, not just the type signature. |

| "I need to see the API shape first" | Spike freely, then delete and rebuild test-first. A throwaway spike is research, not implementation. | Spike, discard, then TDD the real implementation from what you learned. |

Evidence Required

Before claiming TDD is done, show ALL of these:

  • [ ] Failing test output (Red phase): the test name and failure message
  • [ ] Passing test output (Green phase): with the same test name
  • [ ] Test covers behavior, not implementation (no mocking internals)
  • [ ] Refactor step completed OR explicitly noted as unnecessary with reason

No evidence = not done. "I wrote tests" without showing output is not TDD.

Red Flags

  • Writing implementation before any test exists
  • Test that tests implementation details instead of behavior
  • Skipping the refactor step
  • Multiple behaviors in one test

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

同名技能的其他版本

有 3 个不同仓库或目录里都有叫 tdd 的技能。它们内容并不相同,别混用: