Files
2nd/10_Wiki/Topic_Programming/AI_and_ML/Test-Driven_Development.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

4.8 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-test-driven-development Test-Driven Development 10_Wiki/Topics verified self
TDD
Red-Green-Refactor
test first
none A 0.9 applied
tdd
testing
software-engineering
ai-aided
2026-05-10 pending
language framework
python pytest

Test-Driven Development

매 한 줄

"매 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

  1. Red: 매 failing test 의 write (no impl yet).
  2. Green: 매 minimum code 의 test 의 pass.
  3. 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.

매 응용

  1. Greenfield library — 매 API design 의 test 의 drive.
  2. Bug fix — 매 reproducing test 먼저 write.
  3. AI agent — 매 spec → test → impl 매 deterministic loop.

💻 패턴

Pytest red-green-refactor

# tests/test_pricing.py
import pytest
from pricing import discount_price

def test_no_discount_for_zero_qty():
    assert discount_price(100, qty=0) == 100

def test_10pct_discount_at_qty_10():
    assert discount_price(100, qty=10) == 90.0
# pricing.py — minimum impl after red
def discount_price(price: float, qty: int) -> float:
    if qty >= 10:
        return price * 0.9
    return price

Parametrize

@pytest.mark.parametrize("qty,expected", [
    (0, 100), (1, 100), (9, 100),
    (10, 90), (50, 90), (100, 80),
])
def test_discount_table(qty, expected):
    assert discount_price(100, qty=qty) == expected

Fixture + integration test

@pytest.fixture
def db():
    conn = sqlite3.connect(":memory:")
    conn.execute("CREATE TABLE orders (id INT, total REAL)")
    yield conn
    conn.close()

def test_save_order(db):
    save_order(db, id=1, total=99.0)
    row = db.execute("SELECT total FROM orders WHERE id=1").fetchone()
    assert row[0] == 99.0

Property-based (Hypothesis)

from hypothesis import given, strategies as st

@given(st.floats(min_value=0, max_value=1e6), st.integers(min_value=0, max_value=1000))
def test_discount_never_exceeds_price(price, qty):
    assert discount_price(price, qty) <= price

TypeScript / Vitest

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 pseudocode
while not all_green:
    test = agent.generate_test(spec)
    write_file(test)
    run_pytest()  # expect FAIL
    impl = agent.generate_impl_to_pass(test)
    write_file(impl)
    if run_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.

🔗 Graph

🤖 LLM 활용

언제: 매 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).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — TDD red-green-refactor + property-based + AI agent loop