tdd
测试驱动开发。适用于用户想用先写测试的方式构建功能或修复缺陷、提到 “red-green-refactor”,或需要集成测试时。
Security Assessment
Detected risks:
About tdd
A Simplified Chinese localization of a test-driven development guide organized around the red-green-refactor loop. It is intended for building features or fixing bugs test-first, for teams that want integration-style tests, and for anyone who asks specifically for the red-green-refactor discipline. The prose and checklists are written in Chinese, though code and technical terms remain in English.
Its philosophy is that tests should verify behavior through public interfaces, not implementation details, so that code can be rewritten freely without breaking the suite. Good tests read like a specification of what the system does and survive refactors; bad tests bind to internals by mocking collaborators, testing private methods, or verifying through side channels such as querying the database directly - the warning sign being a test that fails after a behavior-preserving refactor or an internal rename. A central section attacks the horizontal-slicing anti-pattern of writing all tests first and then all implementation, which tends to test the imagined shape of data and signatures rather than real, user-facing behavior; the prescribed alternative is vertical slices via tracer bullets, one test to one implementation, each test informed by what the previous cycle taught.
The workflow moves from planning - agreeing with the user on interface changes and the priority-ordered behaviors to test, designing for testability and deep modules - through a first tracer-bullet test that proves the path works end to end, into an incremental RED-to-GREEN loop where only enough code is written to pass the current test and no speculative features are added. Refactoring comes only once tests are green, never in a RED state. A per-cycle checklist reinforces the rules, and companion reference files cover tests, mocking, deep modules, interface design, and refactoring in more depth.
FAQ
What development loop does it follow?
The red-green-refactor loop: write a failing test (RED), write minimal code to make it pass (GREEN), then refactor once everything is green.
What is the main anti-pattern it warns against?
Horizontal slicing, meaning writing all tests first and then all implementation. It instead advocates vertical slices via tracer bullets, pairing one test with one implementation at a time.
Should tests target implementation or behavior?
Behavior, verified through public interfaces. Good tests survive internal refactors, and if renaming an internal function breaks a test, that test was checking implementation rather than behavior.
When is it safe to refactor?
Only after all tests pass, in the GREEN state. The guide is explicit that you should never refactor while a test is failing (RED).
What language is the guidance written in?
The instructions, philosophy, and checklists are written in Simplified Chinese as a zh-cn localization, while code samples and key technical terms stay in English.
Install tdd
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
vinvcn/mattpocock-skills-zh-cn