eng-tdd
1
总安装量
1
周安装量
#77964
全站排名
安装命令
npx skills add https://github.com/tjboudreaux/cc-plugin-engineering-excellence --skill eng-tdd
Agent 安装分布
amp
1
cline
1
opencode
1
cursor
1
kimi-cli
1
codex
1
Skill 文档
Test-Driven Development (TDD)
Overview
Write the test first. Watch it fail. Implement just enough to pass. Refactor while staying green. If you didnât see the test fail, you donât know whether it tests the right behavior.
Iron Law
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Wrote code before the test? Delete it. Start from tests.
When to Use
- Every feature, bug fix, refactor, or behavior change.
- Exceptions only with explicit human approval (throwaway prototypes, generated code, etc.).
Red-Green-Refactor Cycle
- RED â Write one minimal test describing desired behavior.
- Clear, specific name.
- Tests real behavior (avoid unnecessary mocks).
- Verify RED â Run the test; confirm it fails for the expected reason.
- GREEN â Write the simplest code to make the test pass. No extra features.
- Verify GREEN â Run the test suite; ensure the new test and existing tests pass.
- REFACTOR â Clean up code/tests while keeping everything green.
- Repeat for next behavior.
Good vs Bad Tests
| Good | Bad |
|---|---|
| Tests one thing | Vague âdoes workâ |
| Clear name | test1 |
| Real behavior | Asserts on mocks |
Why Order Matters
- Tests written after code pass immediately â prove nothing.
- Manual testing isnât reproducible evidence.
- Keeping prewritten code âfor referenceâ breaks TDDâdelete and rebuild from tests.
Rationalization Countermeasures
| Excuse | Response |
|---|---|
| âToo simpleâ | Simple code breaksâtest anyway. |
| âIâll test laterâ | Tests-after confirm existing behavior, not requirements. |
| âManual testing is enoughâ | No record or rerun; automation is required. |
| âDeleting work is wastefulâ | Sunk cost; untested code is debt. |
| âBeing pragmaticâ | TDD prevents debugging hell; pragmatism = reliability. |
Verification Checklist
- Every new behavior guarded by a test.
- Saw each test fail before implementation.
- Each failure was due to missing behavior (not typos).
- Wrote minimal code to make each test pass.
- Full suite green after changes.
- Refactors done only while green.
- Tests cover edge/error cases.
Failed any item? You skipped TDDâstart over.
Integrating Bug Fixes
- Reproduce bug with a failing test first.
- Apply fix to satisfy the test.
- Keep the test to prevent regressions.
Final Rule
Production code exists only alongside a test that failed before the code was written. Otherwise, redo it with TDD.