AGENT SKILL

test-driven-development

Use when implementing a feature, bugfix, or behavior-changing refactor — require a failing behavior test before production code, then make the smallest change that passes.

License 许可
MIT
最近更新
2026-08-20
Stars
★ 0
Forks
0

01 前言 Front Matter

name
test-driven-development
description
Use when implementing a feature, bugfix, or behavior-changing refactor — require a failing behavior test before production code, then make the smallest change that passes.

03 SKILL.md 正文

Test-Driven Development

Iron Law

<HARD-GATE> NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST. The test must fail because the required behavior is missing. If it passes immediately or fails to compile, it is not RED. </HARD-GATE>

Use for features, bugfixes, and behavior-changing refactors. Skip documentation, pure configuration, and explicitly throwaway prototypes.

Loop

  1. RED — write the smallest test of observable behavior; run it and inspect the expected failure.
  2. GREEN — write minimum production code; do not add adjacent improvements.
  3. REFACTOR — improve names and structure without new behavior.
  4. VERIFY — run the full relevant test file, then required type/lint checks.

A behavior test checks input/output, state change, side effect, or error contract. It must survive internal refactoring.

Work in the smallest vertical slice: one behavior through the relevant layers. Name the next observable check in one sentence; if you cannot, split it smaller. Finish RED/GREEN verification before starting another slice.

Test Design Rules

  • Test behavior, not mocks. A mock-call assertion alone proves wiring, not the promised outcome.
  • Mock at the seam. Replace an external interface, not private internals.
  • No test-only methods in production. Inject the dependency or expose a real domain operation instead.
  • One intent per test. Multiple assertions are fine when they prove one outcome.
  • Keep tests order-independent. No shared mutable fixtures or reliance on another test running first.
  • Use a contract test before mocking an unfamiliar dependency. Know what the real dependency does.

Tautology Check

Ask: Would this test fail if I deleted or broke the production body? If not, it is a tautology. A test that merely repeats the implementation, snapshots without intent, or checks toHaveBeenCalled can pass while behavior is wrong.

Common Rationalizations

Rationalization Counter
“It is obvious.” Then RED is cheap. Run it.
“Tests after.” A passing-after test does not prove it detects the defect.
“Manual testing passed.” It is not reproducible or regression-safe.
“Mocking is faster.” Mock only a known seam; assert the resulting behavior.
“Existing tests cover it.” Run them and cite the result.

Stop Conditions

Stop if RED fails for the wrong reason, the test requires private access, or GREEN needs unrelated behavior. Repair the test or design before continuing.

Completion Evidence

Report the observed RED failure, the GREEN command/output, and the final relevant verification. No evidence means no completion claim.

04 同仓库更多 Skills

MinhDuyDEV
MinhDuyDEV/md-pikit

writing-skills

Use when creating new skills, editing existing skills, or verifying skills work before deployment - applies TDD to process documentation by testing with subagents before writing, iterating until bulletproof against rationalization. Includes complete pressure testing methodology.

★ 0
MinhDuyDEV
MinhDuyDEV/md-pikit

verification-before-completion

Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

★ 0
MinhDuyDEV
MinhDuyDEV/md-pikit

typescript-coding-standards

Use when writing, refactoring, or reviewing TypeScript code that needs strong domain modeling, typed errors, schema parsing, safe adapters, test seams, or maintainable module boundaries.

★ 0
MinhDuyDEV
MinhDuyDEV/md-pikit

source-driven-development

Use when unfamiliar libraries, dependency internals, external APIs, framework behavior, migrations, or current ecosystem guidance require official documentation, version-matched source, read the tests, and cited evidence.

★ 0
MinhDuyDEV
MinhDuyDEV/md-pikit

security-and-hardening

Use when auditing security, implementing authentication or authorization, handling secrets, or validating data across external trust boundaries.

★ 0
MinhDuyDEV
MinhDuyDEV/md-pikit

prototype

Use when the user wants to prototype, sanity-check a data model or state machine, mock up a UI, explore design options, or says "prototype this", "let me play with it", "try a few designs".

★ 0