test-driven-development
하는 일
이 가이드는 에이전트가 동작을 고치거나 새 동작을 추가하는 코드를 쓰기 전에, 실패하는 테스트를 먼저 쓰게 합니다. 변경이 작동하고 다른 것을 망가뜨리지 않는다는 증명을 원하는 개발자를 위한 가이드입니다.
사용하는 경우
- ✓새 로직을 추가하거나 기존 동작을 바꾸라고 에이전트에게 요청할 때.
- ✓버그가 보고되어 수정 전에 테스트로 재현하고 싶을 때.
- ✓현재 동작을 깨지 않으면서 예외 처리를 추가하고 싶은 경우.
스킬 링크
https://github.com/cloudflare/computer/blob/main/.agents/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.
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
export async function completeTask(id: string): Promise<Task> {
return db.tasks.update(id, {
status: 'completed',
completedAt: new Date(), // This was missing
});
}
// Step 3: Test passes → bug fixed, regression guarded
The Test Pyramid
Invest testing effort according to the pyramid — most tests should be small and fast, with progressively fewer tests at higher levels:
╱╲
╱ ╲ E2E Tests (~5%)
╱ ╲ Full user flows, real browser
╱──────╲
╱ ╲ Integration Tests (~15%)
╱ ╲ Component interactions, API boundaries
╱────────────╲
╱ ╲ Unit Tests (~80%)
╱ ╲ Pure logic, isolated, milliseconds each
╱──────────────────╲
The Beyonce Rule: If you liked it, you should have put a test on it. Infrastructure changes, refactoring, and migrations are not responsible for catching your bugs — your tests are. If a change breaks your code and you didn't have a test for it, that's on you.
Test Sizes (Resource Model)
Beyond the pyramid levels, classify tests by what resources they consume:
| Size | Constraints | Speed | Example |
|---|---|---|---|
| Small | Single process, no I/O, no network, no database | Milliseconds | Pure function tests, data tra |
자주 묻는 질문
새 기능에만 쓰나요?
아닙니다. 버그 수정과 기존 동작 변경에도 적용됩니다.
테스트가 왜 먼저 실패해야 하나요?
바로 통과하는 테스트는 아무것도 증명하지 못하므로, 수정 전에 실패하는지 확인합니다.
언제 건너뛰어도 되나요?
순수 설정 변경, 문서 업데이트, 동작 변화가 없는 정적 콘텐츠일 때입니다.
상세 정보
작성자의 원본 설명
Drives development with tests. 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.
repo: cloudflare/computer
인기도
- GitHub 스타
- 9.8k
- 순위
- #12208
- 라이선스
- MIT
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
cloudflare
9.8k에이전트가 작업을 시작하기 전에 Workers, Durable Objects, wrangler 등에 맞는 Cloudflare 플랫폼 가이드를 찾도록 돕습니다.
prose
9.8k에이전트가 코드 주석, 커밋 메시지, README, 문서를 평이한 영어로 쓰도록 가르칩니다. 전문 용어와 기업식 표현을 피합니다.
pull-requests
9.8k에이전트가 변경의 흐름, 해결하는 문제, 확인 방법을 설명하는 명확한 풀 리퀘스트 설명을 쓰도록 가르칩니다.
gardener-tasks
9.8kGitHub Actions에서 AI 유지보수 작업을 실행하는 Gardener 작업 파일을 쓰고 점검하는 방법을 설명합니다.
비슷한 스킬
test-driven-development
311k에이전트가 기능이나 수정을 만들기 전에 실패하는 테스트를 먼저 쓰고, 그것을 통과시키는 가장 작은 코드를 작성하도록 가르칩니다.
verification-before-completion
311k에이전트가 작업, 수정, 빌드가 완료되었거나 통과했다고 말하기 전에 실제 점검을 실행하고 결과를 읽도록 가르칩니다.
migrate-to-shoehorn
310k테스트 파일의 위험한 타입 캐스팅을 shoehorn 라이브러리로 바꿔, 테스트가 일부 데이터만 써도 타입 검사를 통과하도록 돕습니다.