| context | fork |
| name | tdd-workflow |
| description | Test-first discipline for new features, bug fixes, and coverage work.
Auto-activates when tests are requested, TDD is mentioned, or refactoring needs a safety net.
Triggers: test, TDD, test-driven, coverage, unit test, red green refactor, ํ
์คํธ, ์ปค๋ฒ๋ฆฌ์ง,
ํ
์คํธ ๋จผ์ ์จ์ค, TDD๋ก ์ง์ค, ํ
์คํธ ์ปค๋ฒ๋ฆฌ์ง ์ฌ๋ ค์ค
|
| lang | ["en","ko"] |
| platforms | ["claude-code","gemini-cli","codex-cli","cursor"] |
| level | 2 |
| triggers | ["test","TDD","test-driven","coverage","unit test","RED GREEN REFACTOR"] |
| agents | ["tdd-guide","backend-developer"] |
| argument-hint | [target] e.g., auth-service, utils, login-form |
| tokens | ~3K |
| category | testing |
| version | 1.0.0 |
| lastVerified | 2026-06-08 |
| source_hash | b0104fec |
| whenNotToUse | Do not apply the full RED-GREEN-REFACTOR cycle to throwaway scripts, one-off data migrations, or exploratory code that will be deleted within 24 hours. Also skip when adding tests to already-running legacy code under time pressure โ defer to a dedicated coverage sprint instead. |
TDD Workflow
Use $ARGUMENTS to specify the test target (module, service, or component).
Current State
!npm test -- --reporter=dot 2>&1 | tail -5
When This Skill Applies
- Implementing new features (tests first)
- Fixing bugs (reproduction test first)
- Refactoring code (ensure coverage before changing)
- Coverage analysis and improvement
Core Guidance
Cycle: RED (failing test) -> GREEN (minimal code to pass) -> REFACTOR (improve while green) -> repeat
Coverage Requirements:
| Type | Minimum | Focus |
|---|
| Unit | 80% | Functions, pure logic, utilities |
| Integration | 70% | API endpoints, database ops |
| E2E | Critical paths | User workflows, conversions |
For New Features:
- Write interface/type definition
- Write failing test for first behavior
- Implement minimum code to pass
- Write next failing test, implement, repeat
- Refactor once all behaviors pass
- Verify >= 80% coverage
For Bug Fixes:
- Write failing test that reproduces the bug
- Verify it fails for the right reason
- Fix with minimum change
- Verify test passes, no regressions
Test Quality Rules:
- Test behavior, not implementation
- Single clear assertion focus per test
- Tests independent, runnable in any order
- Mocks minimal, at system boundaries only
Anti-Patterns: Tests after code, testing implementation details, production data in fixtures, over-mocking, skipping edge cases, .skip instead of fixing
Output Template
TDD CYCLE REPORT
=================
Feature: [feature/bug description]
Phase: [RED | GREEN | REFACTOR]
Cycle: [n] of [total]
TEST SCENARIO
โโโโโโโโโโโโโ
Objective: [what behavior is being tested]
Starting Conditions:[preconditions, initial state]
Steps:
1. [action/input]
2. [action/input]
3. [action/input]
Expected Outcome: [precise expected result]
Actual Outcome: [observed result - RED phase only]
TEST INVENTORY
โโโโโโโโโโโโโโ
# | Test Description | Status | Coverage Impact
--|-------------------------------|---------|----------------
1 | [test name/behavior] | [R/G] | [+n% to target area]
2 | [test name/behavior] | [R/G] | [+n% to target area]
3 | [test name/behavior] | [R/G] | [+n% to target area]
COVERAGE STATUS
โโโโโโโโโโโโโโโ
Type | Before | After | Target | Status
โโโโโโโโโโโโโ|โโโโโโโโ|โโโโโโโโ|โโโโโโโโ|โโโโโโโโโโ
Unit | [%] | [%] | 80% | [PASS|FAIL]
Integration | [%] | [%] | 70% | [PASS|FAIL]
Branch | [%] | [%] | 85% | [PASS|FAIL]
REFACTOR NOTES (if REFACTOR phase)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
[1] [what was refactored]: [why, while keeping green]
[2] ...
NEXT CYCLE
โโโโโโโโโโ
[next behavior to test, or "All behaviors covered - ready to ship"]
Workflow Checklist
Copy this checklist and track progress:
Progress:
- [ ] Step 1: Write interface/type definition for the behavior
- [ ] Step 2: Write failing test (RED) โ confirm it fails for the right reason
- [ ] Step 3: Implement minimum code to pass (GREEN)
- [ ] Step 4: Run test suite โ confirm green, no regressions
- [ ] Step 5: Refactor while keeping tests green (REFACTOR)
- [ ] Step 6: Verify coverage >= 80% unit, >= 70% integration
- [ ] Step 7: Commit with descriptive test-first evidence
Human Checkpoints
Checkpoint 1: ํ
์คํธ ๋ฒ์ ๊ฒฐ์ (After Step 1)
Context: ์ธํฐํ์ด์ค/ํ์
์ ์ ์๋ฃ. ์ด๋ค behaviors์ ํ
์คํธ๋ฅผ ์์ฑํ ์ง ๊ฒฐ์ ํ์.
Ask: "์ธํฐํ์ด์ค ์ ์๊ฐ ์๋ฃ๋์์ต๋๋ค. ์ด๋ค ๋ฒ์๋ก ํ
์คํธ๋ฅผ ์์ฑํ ๊น์?"
Options:
- ์ ์ฒด behaviors โ ๋ชจ๋ public method/property ํ
์คํธ
- ๊ณต๊ฐ API๋ง โ ์ธ๋ถ ๋
ธ์ถ ์ธํฐํ์ด์ค๋ง ํ
์คํธ
- ํฌ๋ฆฌํฐ์ปฌ ๊ฒฝ๋ก๋ง โ ํต์ฌ ๋น์ฆ๋์ค ๋ก์ง๋ง ํ
์คํธ
- ์ง์ ์ง์ โ ํ
์คํธํ behaviors ์๋ ์ ํ
Default: 2 (๊ณต๊ฐ API ํ
์คํธ๊ฐ ๋น์ฉ ๋๋น ํจ๊ณผ ์ต์ )
Skippable: Yes โ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์งํ
Freedom: MEDIUM
Checkpoint 2: ํ
์คํธ ์คํจ ๊ฒ์ฆ (After Step 2)
Context: ์คํจ ํ
์คํธ ์์ฑ ์๋ฃ. ์ฌ๋ฐ๋ฅธ ์ด์ ๋ก ์คํจํ๋์ง ํ์ธ ํ์ (์๋ชป๋ ์ด์ ๋ก ์คํจํ๋ฉด ํ
์คํธ ์์ฒด๊ฐ ๊ฒฐํจ).
Ask: "ํ
์คํธ๊ฐ ์คํจํฉ๋๋ค. ์ฌ๋ฐ๋ฅธ ์ด์ ๋ก ์คํจํ๊ณ ์๋์? (๊ตฌํ ๋ถ์ฌ๋ก ์ธํ ์คํจ์ฌ์ผ ํจ)"
Options:
- ์ โ ์์๋๋ก ์คํจ, GREEN ๋จ๊ณ ์งํ
- ์๋์ค โ ๋ค๋ฅธ ์ด์ ๋ก ์คํจ, ํ
์คํธ ์์ ํ์
- ๋ถ๋ถ์ โ ์ผ๋ถ ํ
์คํธ๋ง ์ฌ๋ฐ๋ฅด๊ฒ ์คํจ
Default: 1 (๋๋ถ๋ถ ์ฌ๋ฐ๋ฅธ ์คํจ)
Skippable: No โ RED ๋จ๊ณ์ ํต์ฌ ๊ฒ์ฆ
Freedom: LOW
Checkpoint 3: ๋ฆฌํฉํ ๋ง ๋ฒ์ ๊ฒฐ์ (After Step 5)
Context: ๋ชจ๋ ํ
์คํธ ํต๊ณผ(GREEN). ๋ฆฌํฉํ ๋ง ๊ธฐํ๊ฐ ๋ฐ๊ฒฌ๋จ.
Ask: "๋ฆฌํฉํ ๋ง ๊ธฐํ N๊ฐ๋ฅผ ๋ฐ๊ฒฌํ์ต๋๋ค. ์ด๋ค ๋ฒ์๋ก ๋ฆฌํฉํ ๋งํ ๊น์?"
Options:
- ์ ์ฒด ์ ์ฉ โ ๋ฐ๊ฒฌ๋ ๋ชจ๋ ๋ฆฌํฉํ ๋ง ์ํ
- ์ต๋ ํจ๊ณผ๋ง โ ๊ฐ์ฅ ์ํฉํธ ํฐ ํญ๋ชฉ๋ง ์ ์ฉ
- ์ฝ๋ ์ ๋ฆฌ๋ง โ ๋ค์ด๋ฐ, ํฌ๋งทํ
๋ฑ ๊ฒฝ๋ ์ ๋ฆฌ๋ง
- ์คํต โ ํ์ฌ ์ฝ๋ ์ ์ง, ๋ค์ ์ฌ์ดํด๋ก
Default: 2 (์๊ฐ ๋๋น ํจ๊ณผ ์ต์ )
Skippable: Yes โ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์งํ
Freedom: HIGH
Checkpoint 4: ์ปค๋ฒ๋ฆฌ์ง ๊ฐญ ๋์ (After Step 6)
Context: ์ปค๋ฒ๋ฆฌ์ง ์ธก์ ์๋ฃ. ํ๊ฒ ๋ฏธ๋ฌ ์ ๋์ ๊ฒฐ์ ํ์.
Ask: "์ปค๋ฒ๋ฆฌ์ง [X]%. ๊ฐญ์ด ์๋ ์์ญ: [๋ชฉ๋ก]. ์ด๋ป๊ฒ ๋์ํ ๊น์?"
Options:
- ์ ์ฒด ๋ณด์ถฉ โ ๋ชจ๋ ๊ฐญ์ ํ
์คํธ ์ถ๊ฐ
- ํฌ๋ฆฌํฐ์ปฌ๋ง โ ํต์ฌ ๊ฒฝ๋ก ๊ฐญ๋ง ๋ณด์ถฉ
- ํ์ ์ ์ง โ ํ์ฌ ์ปค๋ฒ๋ฆฌ์ง ์์ฉ
- ๋ณ๋ ํ์คํฌ โ ์ปค๋ฒ๋ฆฌ์ง ๊ฐ์ ์ ๋ณ๋ ์์
์ผ๋ก ๋ฑ๋ก
Default: 2 (ํฌ๋ฆฌํฐ์ปฌ ๊ฒฝ๋ก ์ฐ์ )
Skippable: Yes โ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์งํ
Freedom: MEDIUM
Freedom Levels
| Step | Freedom | Guidance |
|---|
| Interface/type definition | HIGH | Design decisions, multiple valid shapes |
| Write failing test | MEDIUM | Behavior focus required, but assertion style flexible |
| Implement to pass | LOW | Minimum code only, no extras |
| Run tests | LOW | Must pass, no skipping |
| Refactor | HIGH | Creative improvement while green |
| Verify coverage | LOW | Thresholds are non-negotiable |
| Commit | MEDIUM | Message style follows convention, scope flexible |
Output Template
TDD CYCLE REPORT
=================
Feature: [feature/bug description]
Cycle: [RED โ GREEN โ REFACTOR]
Date: [date]
TEST RESULTS
------------
Phase | Status | Details
---------|--------|---------------------------
RED | DONE | [test name] โ fails as expected
GREEN | DONE | [implementation] โ test passes
REFACTOR | DONE | [changes made while green]
COVERAGE
--------
Type | Before | After | Delta | Target
--------------|--------|--------|--------|--------
Unit | [n%] | [n%] | [+/-%] | >= 80%
Integration | [n%] | [n%] | [+/-%] | >= 70%
FILES CHANGED
-------------
File | Action | Tests Added
------------------------|----------|------------
[file path] | created | [n]
[file path] | modified | [n]
ANTI-PATTERNS CHECK
--------------------
- [ ] Tests written before code
- [ ] Testing behavior, not implementation
- [ ] No .skip or .only left
- [ ] Mocks at boundaries only
Quick Reference
- Always RED before GREEN
- Every bug fix gets a regression test
- Test names describe expected behavior
- 80%+ unit, 70%+ integration coverage
Rationalizations
The following table captures common excuses agents make to skip critical steps in this skill, paired with factual rebuttals. Use this to catch and resist shortcuts.
| Excuse | Rebuttal |
|---|
| "I'll add tests after the implementation works" | Post-hoc tests confirm your implementation, not the requirement. They encode the bug you wrote, not the behavior the user needs. RED before GREEN is how you prove the test actually catches failure. |
| "This function is too small/trivial to test" | "Trivial" functions are where off-by-one, null-handling, and boundary bugs live. A 3-line test for a 3-line function is still cheaper than a production incident. |
| "The test is obvious โ I can see the code is correct" | Reading is not executing. Type coercion, async ordering, and closure capture routinely fool visual inspection. If it's obvious, the test takes 30 seconds and proves it. |
| "I'll skip RED and write the test after GREEN" | A test that has never failed is a test you cannot trust. You have not proven it actually exercises the code path โ it may pass vacuously. RED is the only way to verify the test is wired correctly. |
| "Refactoring does not need new tests, coverage is already there" | Refactoring changes structure, not behavior โ the existing tests are your safety net. But if coverage is below 80% on the target, you are refactoring blind. Measure first, then refactor. |
| "Mocking the database is too much setup for this test" | Over-mocking is an anti-pattern, but zero mocking at boundaries means your "unit test" is really an integration test pretending to be fast. Use fixtures or in-memory adapters โ not .skip. |
| "The bug is too hard to reproduce in a test" | If you cannot reproduce it in a test, you cannot prove you fixed it. "Hard to reproduce" means you have not yet isolated the state โ that isolation IS the fix. |
Common Rationalizations
| Rationalization | Why it's wrong | What to do instead |
|---|
| "I already know the implementation, tests come after" | Tests written after implementation confirm the code you wrote, not the behavior required; RED phase exists to prove the test is wired correctly | Write the failing test first even if the implementation is mentally obvious โ the 30-second cost is less than the regression it will catch |
| "GREEN phase is done when the test passes, refactoring is optional" | Skipping REFACTOR leaves the codebase in the state it took to pass tests, not the state it should be in long-term; coverage without clarity accumulates debt | Budget at least 5 minutes per cycle for REFACTOR even if the only change is renaming a variable |
| "80% coverage is arbitrary so I'll aim for whatever is natural" | "Whatever is natural" trends to 40% because the natural tendency is to test happy paths; the 80% floor forces testing of error branches and edge cases | Set the coverage threshold in your vitest config so CI enforces it mechanically, not by intention |
| "This module is stable, adding tests will break it" | Adding tests to stable code cannot break it unless the code had untested side effects; such tests are revealing hidden fragility, not creating it | Add characterization tests that record current behavior, then refactor with confidence |
| "Integration tests cover this unit, I don't need unit tests too" | Integration tests are slow and imprecise โ they tell you something is wrong, not where; unit tests tell you which function failed | Keep both layers: unit tests for fast feedback, integration for contract verification |
Red Flags
- Test files committed without a corresponding RED commit in the git log
.skip or .only annotations present in any test file at merge time
- Test names that describe implementation ("calls
saveUser") rather than behavior ("persists a new user to the store")
- Coverage badge below 80% on modules touched in the current PR
- Refactoring commits that also add new features (GREEN and REFACTOR mixed in one commit)
- Mocks that re-implement non-trivial logic rather than stubbing at a boundary