test-driven-development
하는 일
더 안정적으로 코드를 작성하도록 돕습니다. 먼저 실패하는 테스트를 작성하고, 그다음 테스트를 통과시키는 최소한의 코드를 작성하며, 마지막으로 코드를 정리합니다.
사용하는 경우
- ✓새 기능을 만들 때.
- ✓버그를 고칠 때.
- ✓기존 코드를 수정할 때.
스킬 링크
https://github.com/addyosmani/agent-skills/blob/main/skills/test-driven-development/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“팩토리얼을 계산하는 함수에 대한 테스트를 작성한 다음, 함수를 구현해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
먼저 실패할 것이 확실한 테스트를 작성합니다. 그다음 그 테스트를 통과시키는 가장 단순한 코드를 만듭니다. 마지막으로 코드를 검토하고 개선하면서 테스트가 계속 통과하는지 확인합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Test-Driven Development
Overview
Write a failing test before writing the code that makes it pass. For bug fixes, reproduce the bug with a test before attempting a fix. Tests are proof — "seems right" is not done. A codebase with good tests is an AI agent's superpower; a codebase without tests is a liability.
When to Use
- Implementing any new logic or behavior
- Fixing any bug (the Prove-It Pattern)
- Modifying existing functionality
- Adding edge case handling
- Any change that could break existing behavior
When NOT to use: Pure configuration changes, documentation updates, or static content changes that have no behavioral impact.
Related: For browser-based changes, combine TDD with runtime verification using Chrome DevTools MCP — see the Browser Testing section below.
Discover the Stack First
The TDD cycle is universal; the commands are not. Before writing the first test, discover how this repository tests, and use its commands for every RED, GREEN, and verification step:
- Language and build system —
package.json,pom.xml/build.gradle,pyproject.toml,go.mod,Cargo.toml,Gemfile, aMakefile - Checked-in wrappers — prefer
./gradlew,./mvnw,make test, or a repo script over globally installed tools - Test framework and configuration — and how it runs a single focused test vs the full suite
- Existing conventions — where tests live, how files are named, what patterns neighboring tests follow
- Documented commands — README, CONTRIBUTING, and CI workflows show the commands that actually gate merges
Run the repository's focused-test command during the loop and its full-suite command before completion. Never assume a default like npm test — a Gradle, Cargo, or pytest project has its own equivalent.
The examples below use TypeScript for illustration; the workflow is identical in any language once you've discovered the project's own tooling.
The TDD Cycle
RED GREEN REFACTOR
Write a test Write minimal code Clean up the
that fails ──→ to make it pass ──→ implementation ──→ (repeat)
│ │ │
▼ ▼ ▼
Test FAILS Test PASSES Tests still PASS
Step 1: RED — Write a Failing Test
Write the test first. It must fail. A test that passes immediately proves nothing.
// RED: This test fails because createTask doesn't exist yet
describe('TaskService', () => {
it('creates a task with title and default status', async () => {
const task = await taskService.createTask({ title: 'Buy groceries' });
expect(task.id).toBeDefined();
expect(task.title).toBe('Buy groceries');
expect(task.status).toBe('pending');
expect(task.createdAt).toBeInstanceOf(Date);
});
});
Step 2: GREEN — Make It Pass
Write the minimum code to make the test pass. Don't over-engineer:
// GREEN: Minimal implementation
export async function createTask(input: { title: string }): Promise<Task> {
const task = {
id: generateId(),
title: input.title,
status: 'pending' as const,
createdAt: new Date(),
};
await db.tasks.insert(task);
return task;
}
Step 3: REFACTOR — Clean Up
With tests green, improve the code without changing behavior:
- Extract shared logic
- Improve naming
- Remove duplication
- Optimize if necessary
Run tests after every refactor step to confirm nothing broke.
The Prove-It Pattern (Bug Fixes)
When a bug is reported, do not start by trying to fix it. Start by writing a test that reproduces it.
Bug report arrives
│
▼
Write a test that demonstrates the bug
│
▼
Test FAILS (confirming the bug exists)
│
▼
Implement the fix
│
▼
Test PASSES (proving the fix works)
│
▼
Run full test suite (no regressions)
Example:
// Bug: "Completing a task doesn't update the completedAt timestamp"
// Step 1: Write the reproduction test (it should FAIL)
it('sets completedAt when task is completed', async () => {
const task = await taskService.createTask({ title: 'Test' });
const completed = await taskService.completeTask(task.id);
expect(completed.status).toBe('completed');
expect(completed.completedAt).toBeInstanceOf(Date); // This fails → bug confirmed
});
// Step 2: Fix the bug
…
자주 묻는 질문
'Red-Green-Refactor' 주기는 무엇인가요?
1. 실패하는 테스트를 작성한다(Red). 2. 테스트를 통과시키는 최소한의 코드를 작성한다(Green). 3. 테스트를 깨뜨리지 않고 코드를 개선한다(Refactor). 이 과정입니다.
이 방법은 버그를 고치는 데 어떻게 도움이 되나요?
정확한 오류를 보여 주는 테스트를 작성합니다. 테스트가 실패하면 버그가 있다는 것을 알 수 있습니다. 그다음 코드를 고치면 테스트가 통과해야 하며, 이로써 버그가 고쳐졌음이 증명됩니다.
언제 이 도구를 사용하면 안 되나요?
문서 업데이트나 프로그램 동작에 영향을 주지 않는 설정 변경 같은 간단한 수정에는 사용하지 마세요.
상세 정보
작성자의 원본 설명
Drives development with tests using the red-green-refactor loop. Use when implementing any logic, fixing any bug, or changing any behavior. Use when you need to prove that code works, when a bug report arrives, or when you're about to modify existing functionality. Use when asked to add tests to a function, fix a bug in it or change its behavior, even when the code is pasted inline and the request
repo: addyosmani/agent-skills
인기도
- GitHub 스타
- 107k
- 순위
- #784
- 라이선스
- MIT
- 업데이트
- 2026. 10. 13.
댓글
- …
이 저장소의 다른 스킬
api-and-interface-design
107k잘 정의된 API와 인터페이스를 만드는 데 도움을 줍니다. 소프트웨어의 서로 다른 부분이 통신하는 방식을 설계할 때 유용합니다.
browser-testing-with-devtools
107k에이전트가 실제 브라우저에서 코드를 직접 테스트하도록 돕습니다. 사용 환경에서 어떻게 작동하는지 확인하고, 오류와 성능 문제를 찾는 데 유용합니다.
ci-cd-and-automation
107k반복 작업을 자동화하고, 프로젝트를 배포하며, 인프라를 관리하도록 에이전트에게 가르칩니다.
code-review-and-quality
107k여러 측면에서 상세한 코드 검토를 수행합니다. 새 변경 사항을 병합하기 전에 품질을 확인하고 향후 문제를 막는 데 유용합니다.
비슷한 스킬
test-driven-development
311k에이전트가 기능이나 수정을 만들기 전에 실패하는 테스트를 먼저 쓰고, 그것을 통과시키는 가장 작은 코드를 작성하도록 가르칩니다.
verification-before-completion
311k에이전트가 작업, 수정, 빌드가 완료되었거나 통과했다고 말하기 전에 실제 점검을 실행하고 결과를 읽도록 가르칩니다.
migrate-to-shoehorn
310k테스트 파일의 위험한 타입 캐스팅을 shoehorn 라이브러리로 바꿔, 테스트가 일부 데이터만 써도 타입 검사를 통과하도록 돕습니다.