tdd
Test-driven development through agreed seams with a red-to-green loop. Use when a user wants to build a feature or fix using test-first, behavior-focused development.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- tdd
- description
- Test-driven development through agreed seams with a red-to-green loop. Use when a user wants to build a feature or fix using test-first, behavior-focused development.
02 资源文件 6
- 参考文档agents/openai.yaml95 B
- 参考文档deep-modules.md436 B
- 参考文档interface-design.md523 B
- 参考文档mocking.md1.5 KB
- 参考文档refactoring.md460 B
- 参考文档tests.md2.8 KB
03 SKILL.md 正文
Test-Driven Development
Philosophy
Core principle: Tests verify observable behavior through an agreed seam, not implementation details. Code can change entirely; tests should continue to prove what callers experience.
Good tests are integration-style: they exercise real code paths through public APIs. They describe what the system does, not how it does it. A good test reads like a specification - "user can checkout with valid cart" tells you exactly what capability exists. These tests survive refactors because they don't care about internal structure.
Bad tests are coupled to implementation. They mock internal collaborators, test private methods, or verify through external means (like querying a database directly instead of using the interface). The warning sign: your test breaks when you refactor, but behavior hasn't changed. If you rename an internal function and tests fail, those tests were testing implementation, not behavior.
See tests.md for examples, including tautological-test failures, and mocking.md for dependency guidance.
Foundation Guidance
When the software-architecture plugin is installed, use codebase-design as the canonical source for architecture vocabulary and domain-modeling for project language and ADR practices. Do not recreate their definitions here.
These companion skills are optional: if they are unavailable, read the project's existing glossary and ADRs, agree on the test seam in plain language, and continue without creating project documents. Their absence must not block TDD.
Anti-Pattern: Horizontal Slices
DO NOT write all tests first, then all implementation. This is "horizontal slicing" - treating RED as "write all tests" and GREEN as "write all code."
This produces crap tests:
- Tests written in bulk test imagined behavior, not actual behavior
- You end up testing the shape of things (data structures, function signatures) rather than user-facing behavior
- Tests become insensitive to real changes - they pass when behavior breaks, fail when behavior is fine
- You outrun your headlights, committing to test structure before understanding the implementation
Correct approach: Vertical slices via tracer bullets. One test → one implementation → repeat. Each test responds to what you learned from the previous cycle. Because you just wrote the code, you know exactly what behavior matters and how to verify it.
WRONG (horizontal):
RED: test1, test2, test3, test4, test5
GREEN: impl1, impl2, impl3, impl4, impl5
RIGHT (vertical):
RED→GREEN: test1→impl1
RED→GREEN: test2→impl2
RED→GREEN: test3→impl3
...
Workflow
1. Agree the Test Surface
Before writing a test, agree on the seam and the ordered observable behaviors to prove. This agreement may come from an approved specification, an existing contract, or direct user confirmation; do not infer it from an implementation sketch.
Record or confirm:
- [ ] The caller-facing seam that the test will cross
- [ ] A one-line note for each proposed seam explaining what it catches and what it misses
- [ ] The behavior's observable outcome and constraints
- [ ] A prioritized list of behaviors, starting with the smallest valuable path
- [ ] Which dependency substitutes, if any, are justified at external seams
- [ ] Project domain terms and relevant ADR constraints
Ask: "Which seam will callers cross, and which observable behaviors matter most to prove first?"
You can't test everything. Focus on the critical paths and complex logic, not every possible edge case or implementation step.
2. Reject Tautological Tests
A test is tautological when it passes because its setup already guarantees the assertion rather than because production behavior was exercised. Common signs include asserting the value configured on a mock, verifying only a call to an internal collaborator, repeating the implementation's conditional logic in the test, or recomputing the expected value the way the code computes it (expect(add(a, b)).toBe(a + b)). Expected values must come from an independent source of truth: a known-good literal, a worked example, or the spec.
A tautological test can fail when its fixture is wrong, but it supplies no evidence that the system works for a caller. Rewrite it to cross the agreed seam and assert a meaningful observable outcome. See tests.md for examples.
3. Tracer Bullet
Write ONE test that confirms ONE thing about the system:
RED: Write test for first behavior → test fails
GREEN: Write minimal code to pass → test passes
This is your tracer bullet - proves the path works end-to-end.
4. Incremental Loop
For each remaining behavior:
RED: Write next test → fails
GREEN: Minimal code to pass → passes
Rules:
- One test at a time
- Only enough code to pass current test
- Don't anticipate future tests
- Keep tests focused on observable behavior
5. Follow-on Refactoring
Refactoring is not a third phase of the TDD loop. After a behavior increment is green, stop the red-to-green loop before taking up structural changes. Handle them in an explicitly scoped refactoring or review activity, using refactor candidates as input and rerunning relevant tests after each change.
Do not use an anticipated refactor to justify speculative production code in the current behavior increment.
Checklist Per Cycle
[ ] Test describes behavior, not implementation
[ ] Test uses public interface only
[ ] Test would survive internal refactor
[ ] Test would fail if the observable behavior regressed
[ ] Test does not merely assert its own fixture or mock configuration
[ ] Code is minimal for this test
[ ] No speculative features added
04 同仓库更多 Skills
ui-ux-pro-max
UI/UX design intelligence for web and mobile. Local database with 79 searchable styles (88 catalog entries), 192 color palettes, 74 font pairings, 192 product types, 119 UX guidelines, 105 curated icon entries, 17 GSAP motion presets, and 25 chart types across 22 stacks (React, Next.js, Vue, Nuxt, Svelte, Astro, SwiftUI, React Native, Flutter, Tailwind, shadcn/ui, Jetpack Compose, Angular, Laravel, JavaFX, WPF, WinUI, Avalonia, Uno Platform, UWP, Three.js, and HTML/CSS). Use when designing, building, or reviewing UI: pages, components, color schemes, typography, layout, accessibility, animation, or data visualization.
figma-mcp
Implement or compare UI against Figma designs using an available Figma MCP integration. Use for Figma-backed implementation, design-token extraction, or visual-parity gap analysis; Figma MCP access is optional and must already be configured by the user.
improve-codebase-architecture
Find evidence-based, active-change architecture improvements using shared design and domain-modeling guidance. Use when a user wants to reduce architectural friction, deepen a module, or make a current change safer, more testable, and easier to navigate.
domain-modeling
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing GLOSSARY.md or CONTEXT.md, or recording or editing an ADR.
codebase-design
Provide the shared vocabulary and discipline for designing deep modules with clear interfaces and seams. Use when a user wants to design or improve a module, find deepening opportunities, choose a seam, or make code more testable and AI-navigable.
test-coverage-review
MUST invoke to review whether added or updated tests cover code changes in a diff. Checks new logic, branches, error paths, and regression risk, producing a change-to-test matrix. Use requirements-to-tests-traceability for acceptance-criteria mapping and orchestrated-review for bundled reviews.