"매 Red → Green → Refactor — 매 minute scale 의 design loop". Kent Beck 의 Test-Driven Development: By Example (2002) 에서 codified 된 micro-cycle. 매 failing test (Red) → minimum code 로 pass (Green) → smell 제거 (Refactor) 의 30초~3분 사이클이 매 production-grade XP/TDD 의 atomic unit 이다.
매 핵심
매 세 phase
Red: 매 새 behavior 를 실패하는 test 로 명시. Compile error 도 Red 로 인정 (Beck).
Green: 매 fastest path 로 pass — fake it, obvious implementation, triangulation 중 택 1. 매 ugly OK.
Refactor: 매 두 hat 의 second hat — duplicate 제거, naming, 추상화. 매 test 는 계속 green.
매 cycle 시간
매 한 cycle = 30초 ~ 3분 권장. 30분 넘으면 step too big.
매 commit 단위 = green 직후 또는 refactor 직후. Red 상태 commit 의 X.
매 응용
Outside-in (London school): mock 기반 acceptance test → unit drill-down.
Inside-out (Detroit/Chicago school): domain core 부터 state-based test.
AI pair: 매 Claude Code 가 test 작성, 매 human 이 implementation 확인 — 또는 reverse.
💻 패턴
Vitest 의 매 cycle 예시
// === RED ===
import{describe,it,expect}from'vitest';import{Money}from'./money';describe('Money',()=>{it('multiplies amount by scalar',()=>{expect(newMoney(5,'USD').times(2)).toEqual(newMoney(10,'USD'));});});// → fails: Money is not defined
Green: 매 fastest path
// money.ts — Beck 의 "fake it" 단계
exportclassMoney{constructor(publicamount: number,publiccurrency: string){}times(n: number):Money{returnnewMoney(this.amount*n,this.currency);}// equals 는 Vitest 의 toEqual 가 structural 로 처리
}
// 매 두 번째 test 가 generalization 을 강제
it('multiplies by 3',()=>{expect(Money.of(5,'USD').times(3)).toEqual(Money.of(15,'USD'));});// → 매 hardcoded `return new Money(10, ...)` 는 더 이상 통하지 않음
Tidy First (Beck 2023)
// 매 refactor 와 behavior change 를 별도 commit 으로 분리
// 1. tidy first: rename, extract — pure structural
// 2. behavior: 새 test + impl
// 매 PR review 의 noise 감소
TCR (test && commit || revert) — Beck 2018
# 매 hardcore variant: green 이면 commit, red 이면 코드 폐기
vitest run && git commit -am wip || git checkout -- .
AI-assisted RGR (Claude Code 2026)
// 1. human: write Red test
// 2. claude: minimal Green implementation
// 3. human: review + suggest refactor
// 4. claude: apply Extract Function, etc.
// 매 test 의 contract 는 human 이 own
언제: 매 well-bounded pure function, 매 algorithm, 매 domain logic. Claude Code 의 Green phase delegation 효율 높음.
언제 X: 매 UI snapshot, 매 distributed system race, 매 exploration spike — RGR overhead 가 가치 초과.
❌ 안티패턴
Test after: 매 implementation 후 test 추가 — 매 design feedback loss, 매 false-confidence test.
Commit at Red: 매 broken main, 매 bisect 불가.
Skipping Refactor: 매 green-and-go — 매 debt 누적.
Big Red: 매 30분 짜리 test → step too big, 매 walking skeleton 으로 분해.
Refactor with failing test: 매 두 hat 의 violation — 매 behavior change 와 cleanup 혼합.
🧪 검증 / 중복
Verified: Beck TDD: By Example (2002), Tidy First (2023). Martin Fowler Refactoring 2e (2018) Ch.1.
신뢰도 A.
🕓 Changelog
날짜
변경
2026-05-08
Phase 1
2026-05-10
Manual cleanup — full RGR cycle, patterns, Tidy First/TCR variants