TDD Skill
General-purpose Test-Driven Development workflow for product code.
Rule
For implementation work, TDD is the default.
- Do not start with production code changes.
- Start with a test plan, then failing tests (
RED), then minimum code (GREEN), then cleanup (REFACTOR).
- Only skip TDD when the user explicitly says tests are out of scope.
TDD Config Bootstrap (MANDATORY)
Persist TDD preference in the same tracking config hierarchy used by create/plan/run:
.agent/tracking.config.json
${ICA_HOME}/tracking.config.json
$HOME/.codex/tracking.config.json or $HOME/.claude/tracking.config.json
Behavior:
- If project config is missing, ask explicitly:
- "Use system tracking config for this project, or create a project-specific backend config?"
- On first TDD invocation, if selected config file does not exist, create it.
- If
tdd.enabled is missing, ask explicitly and persist:
- "TDD is active. Set default TDD behavior to enabled for this scope/config? (yes/no)"
- Write/update:
{
"tdd": { "enabled": true }
}
- Scope-level decision always takes precedence over stored default for current run.
- If user asks to change default later, update
tdd.enabled in the selected config file and confirm.
When to Use
- User asks for TDD, test-first, or red-green-refactor
- Implementing a new feature with clear behavior
- Fixing a bug and preventing regression
- Refactoring code while preserving behavior
- Working in unfamiliar code where tests reduce risk
When Not to Use
- One-off prototypes where tests are explicitly out of scope
- Tasks with no practical automated verification path
- Purely cosmetic edits where behavior does not change
Core Loop: Red -> Green -> Refactor
Define a single behavior slice
- Capture one user-visible outcome at a time.
- Prefer smallest meaningful increment.
Write a failing test first (RED)
- Add or update one focused test.
- Run the narrowest command that executes the test.
- Confirm it fails for the expected reason.
Implement the minimum code to pass (GREEN)
- Change only what is needed to satisfy the test.
- Avoid speculative abstractions.
- Re-run the focused test, then nearby tests.
Improve design without changing behavior (REFACTOR)
- Remove duplication and improve naming/structure.
- Keep tests green after each small refactor step.
Repeat
- Add the next failing test for the next behavior slice.
- Continue until acceptance criteria are covered.
Acceptance Tests (for this skill)
| Test ID |
Type |
Prompt / Condition |
Expected Result |
| T1 |
Positive trigger |
"Implement this in TDD" |
skill triggers |
| T2 |
Positive trigger |
"Write tests first, then code" |
skill triggers |
| T3 |
Positive trigger |
"Red green refactor this bug fix" |
skill triggers |
| T4 |
Negative trigger |
"Polish this dashboard layout" |
skill does not trigger |
| T5 |
Negative trigger |
"Draft release notes only" |
skill does not trigger |
| T6 |
Behavior |
skill triggered for code change |
requires test plan + RED evidence before implementation |
| T7 |
Behavior |
bug fix workflow |
regression test added first, initially failing |
| T8 |
Behavior |
completion |
reports failing-to-passing evidence and final suite result |
Test Planning Pattern (implementation work)
Before coding, define lightweight acceptance checks:
| Test ID |
Type |
Scenario |
Expected Result |
| T1 |
Happy path |
valid input |
expected output returned |
| T2 |
Edge case |
boundary input |
stable, correct behavior |
| T3 |
Error path |
invalid input |
safe, explicit failure |
| T4 |
Regression |
previously broken flow |
bug stays fixed |
Practical Rules
- Start with behavior, not internal implementation details.
- Use deterministic tests (no flaky timing/network dependencies).
- Keep tests readable (Arrange -> Act -> Assert).
- For bug fixes, write the regression test before the code fix.
- For legacy code, write characterization tests first, then refactor.
- Run full relevant test suite before finishing.
- Record the command/output proving the first failing test run.
- Record the command/output proving the final passing run.
Validation Checklist
Output Contract
When this skill is used, produce:
- Test plan (happy path, edge, error, regression)
- Evidence of initial failing test(s)
- Code change summary tied to passing tests
- Final test results and residual risks (if any)
1---2name: tdd3description: "Activate when user asks for Test-Driven Development, test-first implementation, red-green-refactor, or enforcing tests before code. Use for feature work, bug fixes, and refactors; treat TDD as the default rule unless the user explicitly waives it."4category: "process"5scope: "development"6subcategory: "workflow"7tags:8 - development9 - process10 - tdd11version: "10.2.15"12author: "Karsten Samaschke"13contact-email: "karsten@vanillacore.net"14website: "https://vanillacore.net"15---1617# TDD Skill1819General-purpose Test-Driven Development workflow for product code.2021## Rule2223For implementation work, TDD is the default.24- Do not start with production code changes.25- Start with a test plan, then failing tests (`RED`), then minimum code (`GREEN`), then cleanup (`REFACTOR`).26- Only skip TDD when the user explicitly says tests are out of scope.2728## TDD Config Bootstrap (MANDATORY)2930Persist TDD preference in the same tracking config hierarchy used by create/plan/run:311. `.agent/tracking.config.json`322. `${ICA_HOME}/tracking.config.json`333. `$HOME/.codex/tracking.config.json` or `$HOME/.claude/tracking.config.json`3435Behavior:36- If project config is missing, ask explicitly:37 - "Use system tracking config for this project, or create a project-specific backend config?"38- On first TDD invocation, if selected config file does not exist, create it.39- If `tdd.enabled` is missing, ask explicitly and persist:40 - "TDD is active. Set default TDD behavior to enabled for this scope/config? (yes/no)"41- Write/update:42```json43{44 "tdd": { "enabled": true }45}46```47- Scope-level decision always takes precedence over stored default for current run.48- If user asks to change default later, update `tdd.enabled` in the selected config file and confirm.4950## When to Use5152- User asks for TDD, test-first, or red-green-refactor53- Implementing a new feature with clear behavior54- Fixing a bug and preventing regression55- Refactoring code while preserving behavior56- Working in unfamiliar code where tests reduce risk5758## When Not to Use5960- One-off prototypes where tests are explicitly out of scope61- Tasks with no practical automated verification path62- Purely cosmetic edits where behavior does not change6364## Core Loop: Red -> Green -> Refactor65661. **Define a single behavior slice**67 - Capture one user-visible outcome at a time.68 - Prefer smallest meaningful increment.69702. **Write a failing test first (`RED`)**71 - Add or update one focused test.72 - Run the narrowest command that executes the test.73 - Confirm it fails for the expected reason.74753. **Implement the minimum code to pass (`GREEN`)**76 - Change only what is needed to satisfy the test.77 - Avoid speculative abstractions.78 - Re-run the focused test, then nearby tests.79804. **Improve design without changing behavior (`REFACTOR`)**81 - Remove duplication and improve naming/structure.82 - Keep tests green after each small refactor step.83845. **Repeat**85 - Add the next failing test for the next behavior slice.86 - Continue until acceptance criteria are covered.8788## Acceptance Tests (for this skill)8990| Test ID | Type | Prompt / Condition | Expected Result |91| --- | --- | --- | --- |92| T1 | Positive trigger | "Implement this in TDD" | skill triggers |93| T2 | Positive trigger | "Write tests first, then code" | skill triggers |94| T3 | Positive trigger | "Red green refactor this bug fix" | skill triggers |95| T4 | Negative trigger | "Polish this dashboard layout" | skill does not trigger |96| T5 | Negative trigger | "Draft release notes only" | skill does not trigger |97| T6 | Behavior | skill triggered for code change | requires test plan + RED evidence before implementation |98| T7 | Behavior | bug fix workflow | regression test added first, initially failing |99| T8 | Behavior | completion | reports failing-to-passing evidence and final suite result |100101## Test Planning Pattern (implementation work)102103Before coding, define lightweight acceptance checks:104105| Test ID | Type | Scenario | Expected Result |106| --- | --- | --- | --- |107| T1 | Happy path | valid input | expected output returned |108| T2 | Edge case | boundary input | stable, correct behavior |109| T3 | Error path | invalid input | safe, explicit failure |110| T4 | Regression | previously broken flow | bug stays fixed |111112## Practical Rules113114- Start with behavior, not internal implementation details.115- Use deterministic tests (no flaky timing/network dependencies).116- Keep tests readable (Arrange -> Act -> Assert).117- For bug fixes, write the regression test before the code fix.118- For legacy code, write characterization tests first, then refactor.119- Run full relevant test suite before finishing.120- Record the command/output proving the first failing test run.121- Record the command/output proving the final passing run.122123## Validation Checklist124125- [ ] Tests were written/updated before implementation changes126- [ ] First test run failed for expected reason127- [ ] Minimal implementation made tests pass128- [ ] Refactor preserved green test state129- [ ] New behavior and regression paths are covered130- [ ] Relevant suite passes end-to-end131132## Output Contract133134When this skill is used, produce:1351361. Test plan (happy path, edge, error, regression)1372. Evidence of initial failing test(s)1383. Code change summary tied to passing tests1394. Final test results and residual risks (if any)