본문으로 건너뛰기
Skillpedia
테스트48k · #5939

tdd

하는 일

이 도구는 더 신뢰성 있게 코드를 만드는 데 도움을 줍니다. 실제 코드보다 테스트를 먼저 작성해 모든 것이 기대대로 작동하도록 합니다.

사용하는 경우

  • ✓새 기능이 올바르게 작동하는지 확실히 하고 싶을 때.
  • ✓버그를 고치고 다시 나타나지 않도록 확인해야 할 때.
  • ✓'red-green-refactor'를 듣고 이해하고 싶은 경우.

스킬 링크

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tdd/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“로그인 기능에 대한 테스트를 작성한 다음, 그 테스트를 통과하는 코드를 만들어 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

먼저 코드가 무엇을 해야 하는지 설명하는 테스트를 작성합니다. 코드가 아직 없으므로 이 테스트는 실패합니다. 그다음 테스트를 통과하는 데 필요한 최소한의 코드를 작성합니다. 마지막으로 테스트를 깨뜨리지 않고 코드를 개선할 수 있습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Test-Driven Development

When to Use

Use when this workflow matches the user request: Use this skill for its documented workflow.

Source: mattpocock/skills (MIT).

Philosophy

Core principle: Tests should verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't.

Good tests are integration-style: they exercise real code paths through public APIs. They describe what the system does, not how it does it. A good test reads like a specification - "user can checkout with valid cart" tells you exactly what capability exists. These tests survive refactors because they don't care about internal structure.

Bad tests are coupled to implementation. They mock internal collaborators, test private methods, or verify through external means (like querying a database directly instead of using the interface). The warning sign: your test breaks when you refactor, but behavior hasn't changed. If you rename an internal function and tests fail, those tests were testing implementation, not behavior.

See tests.md for examples and mocking.md for mocking guidelines.

Anti-Pattern: Horizontal Slices

DO NOT write all tests first, then all implementation. This is "horizontal slicing" - treating RED as "write all tests" and GREEN as "write all code."

This produces crap tests:

  • Tests written in bulk test imagined behavior, not actual behavior
  • You end up testing the shape of things (data structures, function signatures) rather than user-facing behavior
  • Tests become insensitive to real changes - they pass when behavior breaks, fail when behavior is fine
  • You outrun your headlights, committing to test structure before understanding the implementation

Correct approach: Vertical slices via tracer bullets. One test → one implementation → repeat. Each test responds to what you learned from the previous cycle. Because you just wrote the code, you know exactly what behavior matters and how to verify it.

WRONG (horizontal):
  RED:   test1, test2, test3, test4, test5
  GREEN: impl1, impl2, impl3, impl4, impl5

RIGHT (vertical):
  RED→GREEN: test1→impl1
  RED→GREEN: test2→impl2
  RED→GREEN: test3→impl3
  ...

Workflow

1. Planning

When exploring the codebase, read CONTEXT.md (if it exists) so that test names and interface vocabulary match the project's domain language, and respect ADRs in the area you're touching.

Before writing any code:

  • Confirm with user what interface changes are needed
  • Confirm with user which behaviors to test (prioritize)
  • Identify opportunities for deep modules (small interface, deep implementation) — run the /codebase-design skill for the vocabulary and the testability checks
  • List the behaviors to test (not implementation steps)
  • Get user approval on the plan

Ask: "What should the public interface look like? Which behaviors are most important to test?"

You can't test everything. Confirm with the user exactly which behaviors matter most. Focus testing effort on critical paths and complex logic, not every possible edge case.

2. Tracer Bullet

Write ONE test that confirms ONE thing about the system:

RED:   Write test for first behavior → test fails
GREEN: Write minimal code to pass → test passes

This is your tracer bullet - proves the path works end-to-end.

3. Incremental Loop

For each remaining behavior:

RED:   Write next test → fails
GREEN: Minimal code to pass → passes

Rules:

  • One test at a time
  • Only enough code to pass current test
  • Don't anticipate future tests
  • Keep tests focused on observable behavior

4. Refactor

After all tests pass, look for refactor candidates:

  • Extract duplication
  • Deepen modules (move complexity behind simple interfaces)
  • Apply SOLID principles where natural
  • Consider what new code reveals about existing code
  • Run tests after each refactor step

Never refactor while RED. Get to GREEN first.

Checklist Per Cycle

[ ] Test describes behavior, not implementation
[ ] Test uses public interface only
[ ] Test would survive internal refactor
[ ] Code is minimal for this test
[ ] No speculative features added

Limitations

  • Requires the upstream tool, account, API key, or local setup when the workflow names one.

…

자주 묻는 질문

'red-green-refactor'란 무엇인가요?

하나의 주기입니다. 'Red'는 테스트가 실패하는 상태, 'Green'은 테스트가 통과하는 상태, 'Refactor'는 동작을 바꾸지 않고 코드를 개선하는 것입니다.

왜 테스트를 먼저 쓰나요?

사용자가 실제로 필요로 하는 것을 만들고 있는지, 코드가 기대대로 작동하는지 확인하게 되며, 나중에 변경하기도 쉬워집니다.

모든 테스트를 한꺼번에 써도 되나요?

권장하지 않습니다. 가장 좋은 방법은 테스트 하나를 쓰고, 그것을 통과하는 코드를 쓰고, 이를 반복하는 것입니다. 그래야 코드 구조가 아니라 실제 동작을 테스트하게 됩니다.

상세 정보

작성자의 원본 설명

Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#5939
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬