"매 Red → Green → Refactor 매 fail-first feedback loop". Kent Beck (Extreme Programming, ~2003) origin. 2026 매 AI-pair (Claude Code, Cursor) 의 default mode — agent의 test 먼저 generate 후 implementation 의 iterate.
매 핵심
매 Cycle
Red: 매 failing test 의 write (no impl yet).
Green: 매 minimum code 의 test 의 pass.
Refactor: 매 clean up, 매 test still green.
매 Levels
Unit: pure function, 1 class.
Integration: 매 DB / network boundary.
Acceptance / E2E: 매 user flow.
매 vs BDD
TDD: developer-facing, 매 method-level.
BDD: stakeholder-facing, 매 Given-When-Then, Cucumber/Behave.
매 응용
Greenfield library — 매 API design 의 test 의 drive.
Bug fix — 매 reproducing test 먼저 write.
AI agent — 매 spec → test → impl 매 deterministic loop.
@pytest.fixturedefdb():conn=sqlite3.connect(":memory:")conn.execute("CREATE TABLE orders (id INT, total REAL)")yieldconnconn.close()deftest_save_order(db):save_order(db,id=1,total=99.0)row=db.execute("SELECT total FROM orders WHERE id=1").fetchone()assertrow[0]==99.0
import{test,expect}from'vitest';import{discountPrice}from'./pricing';test('10% discount at qty 10',()=>{expect(discountPrice(100,10)).toBeCloseTo(90);});
AI-aided TDD loop (2026)
# .claude/commands/tdd.md# 1. Write failing test for: $ARGUMENTS# 2. Run pytest (expect red)# 3. Implement minimum code to pass# 4. Run pytest (expect green)# 5. Refactor; ensure still green# 6. Open PR
# Claude Code automated loop pseudocodewhilenotall_green:test=agent.generate_test(spec)write_file(test)run_pytest()# expect FAILimpl=agent.generate_impl_to_pass(test)write_file(impl)ifrun_pytest().passed:agent.refactor()
매 결정 기준
상황
Approach
매 pure function
TDD strict
매 UI tweak
Snapshot + visual diff (TDD overkill)
매 spike / prototype
Skip TDD, 매 throw away
매 bug fix
매 reproducing test 먼저
매 AI agent task
Test-first prompt — 매 verifiable
기본값: 매 TDD for business logic + libraries. 매 visual / experimental code 매 skip.
언제: 매 test generation (Claude Code "write tests for X"). 매 stub from spec. 매 reproducing-test from bug report.
언제 X: 매 LLM의 hallucinate API → 매 test의 wrong. 매 always run + verify red→green.
❌ 안티패턴
Test after: 매 not TDD; 매 confirms current code, 매 design 의 X drive.
Mock everything: 매 test의 verify nothing real.
Brittle tests: 매 implementation detail 의 lock — refactor breaks.
Skipping refactor step: 매 code rot.
AI-generated test without running: 매 false-green.
🧪 검증 / 중복
Verified (Kent Beck "TDD by Example" 2003; Anthropic Claude Code TDD docs 2026).