본문으로 건너뛰기
Skillpedia
테스트107k · #784

test-driven-development

하는 일

더 안정적으로 코드를 작성하도록 돕습니다. 먼저 실패하는 테스트를 작성하고, 그다음 테스트를 통과시키는 최소한의 코드를 작성하며, 마지막으로 코드를 정리합니다.

사용하는 경우

  • ✓새 기능을 만들 때.
  • ✓버그를 고칠 때.
  • ✓기존 코드를 수정할 때.

스킬 링크

https://github.com/addyosmani/agent-skills/blob/main/skills/test-driven-development/SKILL.md

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

사용 방법

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

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

Use this skill to help me: https://github.com/addyosmani/agent-skills/blob/main/skills/test-driven-development/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

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, a Makefile
  • 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.

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬