本文へ移動
cccskills
無料GitHub で公開日本語紹介

test-driven-development

新機能や不具合修正で、先に期待する動作のテストを書き、失敗を確認してから実装します。最小限のコードで成功させ、全体のテストを保ちながら整理するスキルです。

原文原文の説明を見る

Use when implementing any feature or bugfix, before writing implementation code

インストール方法を見る

こんなときに便利

  • 新機能をテストから実装したいとき
  • 不具合をテストで再現して直したいとき
  • テストを保ちながらコードを整理
  • 再発検出用のテストを確かめたいとき

日本語での紹介

できること

実装より先にテストを書くTDD(テスト駆動開発)の手順で、機能追加や不具合修正を進めます。まず期待する動作を一つのテストにし、未実装のために失敗することを確認します。その後、成功に必要な最小限のコードを実装し、テストを通してから重複の削除や名前の改善を行います。不具合では再現用のテストを先に作り、修正を確かめます。完了前には追加したテストだけでなく、プロジェクト全体のテストも実行します。

こんなときに便利

新機能の期待する動作を明確にしたいときや、修正した不具合を再び検出できるテストを残したいときに向いています。既存の動作を確かめながらコードの構造を整理する作業にも使えます。

使い方の例

  • 「空のメールアドレスを拒否するテストを先に書き、失敗を確認してから修正して」
  • 「新機能をテストから実装し、全体のテスト結果も報告して」

注意点

対象プロジェクトのテストを実行できる環境が必要です。使い捨ての試作品、生成コード、設定ファイルで手順を省く場合は、利用者への確認を求めます。テストより先に書いた実装は削除してやり直す方針です。テスト作成・変更時には付属の writing-good-tests.md を参照します。

この紹介文は、公開されている SKILL.md をもとに AI(Claude Haiku)が作成しました。正確な仕様は下の原文を確認してください。

含まれるファイル(2)

  • SKILL.md9.4 KB
  • writing-good-tests.md8.1 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Test-Driven Development (TDD)

Overview

Write the test first. Watch it fail. Write minimal code to pass.

Core principle: If you didn't watch the test fail, you don't know if it tests the right thing.

Violating the letter of the rules is violating the spirit of the rules.

When to Use

Always:

  • New features
  • Bug fixes
  • Refactoring
  • Behavior changes

Exceptions (ask your human partner):

  • Throwaway prototypes
  • Generated code
  • Configuration files

Thinking "skip TDD just this once"? Stop. That's rationalization.

The Iron Law

NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST

Write code before the test? Delete it. Start over.

No exceptions:

  • Don't keep it as "reference"
  • Don't "adapt" it while writing tests
  • Don't look at it
  • Delete means delete

Implement fresh from tests. Period.

Red-Green-Refactor

digraph tdd_cycle {
    rankdir=LR;
    red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
    verify_red [label="Verify fails\ncorrectly", shape=diamond];
    green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
    verify_green [label="Verify passes\nAll green", shape=diamond];
    refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
    next [label="Next", shape=ellipse];

    red -> verify_red;
    verify_red -> green [label="yes"];
    verify_red -> red [label="wrong\nfailure"];
    green -> verify_green;
    verify_green -> refactor [label="yes"];
    verify_green -> green [label="no"];
    refactor -> verify_green [label="stay\ngreen"];
    verify_green -> next;
    next -> red;
}

RED - Write Failing Test

Write one minimal test showing what should happen.

<Good> ```typescript test('retries failed operations 3 times', async () => { let attempts = 0; const operation = () => { attempts++; if (attempts < 3) throw new Error('fail'); return 'success'; };

const result = await retryOperation(operation);

expect(result).toBe('success'); expect(attempts).toBe(3); });

Clear name, tests real behavior, one thing
</Good>

<Bad>
```typescript
test('retry works', async () => {
  const mock = jest.fn()
    .mockRejectedValueOnce(new Error())
    .mockRejectedValueOnce(new Error())
    .mockResolvedValueOnce('success');
  await retryOperation(mock);
  expect(mock).toHaveBeenCalledTimes(3);
});

Vague name, tests mock not code </Bad>

Requirements:

  • One behavior
  • Clear name
  • Real code (no mocks unless unavoidable)

Verify RED - Watch It Fail

MANDATORY. Never skip.

npm test path/to/test.test.ts

Confirm:

  • Test fails (not errors)
  • Failure message is expected
  • Fails because feature missing (not typos)

Test passes? You're testing existing behavior. Fix test.

Test errors? Fix error, re-run until it fails correctly.

GREEN - Minimal Code

Write simplest code to pass the test.

<Good> ```typescript async function retryOperation<T>(fn: () => Promise<T>): Promise<T> { for (let i = 0; i < 3; i++) { try { return await fn(); } catch (e) { if (i === 2) throw e; } } throw new Error('unreachable'); } ``` Just enough to pass </Good> <Bad> ```typescript async function retryOperation<T>( fn: () => Promise<T>, options?: { maxRetries?: number; backoff?: 'linear' | 'exponential'; onRetry?: (attempt: number) => void; } ): Promise<T> { // YAGNI } ``` Over-engineered </Bad>

Don't add features, refactor other code, or "improve" beyond the test.

Verify GREEN - Watch It Pass

MANDATORY.

npm test path/to/test.test.ts

Confirm:

  • Test passes
  • Other tests still pass
  • Output pristine (no errors, warnings)

Test fails? Fix code, not test.

Other tests fail? Fix now.

"Other tests" means the project's suite, not just your file. A green run of the test you wrote is not a green suite. Before you call the change done, run the project's test command (bare pytest, npm test, cargo test — whatever the repo uses) even when your task named only one test file. A scope statement in your task bounds the deliverable, not your verification. Any failure that run shows — including one you didn't cause — goes in your report by name; a red test you watched scroll past and didn't mention is a report falsified by omission.

REFACTOR - Clean Up

After green only:

  • Remove duplication
  • Improve names
  • Extract helpers

Keep tests green. Don't add behavior.

Repeat

Next failing test for next feature.

Good Tests

QualityGoodBad
MinimalOne thing. "and" in name? Split it.test('validates email and domain and whitespace')
ClearName describes behaviortest('test1')
Shows intentDemonstrates desired APIObscures what code should do

When writing or changing any test, read writing-good-tests.md for the rules that keep tests honest:

  • Name the production change that would make the test fail — before writing it
  • Assert on real behavior, never on mock behavior
  • Keep test-only code in test utilities, out of production classes
  • Understand a dependency's side effects before mocking it

Common Rationalizations

ExcuseReality
"Too simple to test"Simple code breaks. Test takes 30 seconds.
"I'll test after"Tests written after pass immediately — which proves nothing. They may test the wrong thing, test the implementation instead of the behavior, or miss the edge case you forgot. You never watched it fail, so you never proved it can catch the bug. Test-first forces that failure.
"Tests after achieve same goals (spirit not ritual)"Tests-after answer "what does this do?"; tests-first answer "what should this do?" Tests written after are biased by the code you already wrote — you verify the cases you remembered, not the ones you'd have discovered. Coverage without proof the tests work.
"Already manually tested"Manual testing is ad-hoc: no record of what you covered, no way to re-run it when the code changes, easy to forget cases under pressure. "Worked when I tried it" ≠ comprehensive. Automated tests run the same way every time.
"Deleting X hours is wasteful"Sunk cost fallacy — that time is already spent either way. The real choice: rewrite with TDD (high confidence) vs. keep it and bolt tests on after (low confidence, likely bugs). Keeping code you can't trust is the waste.
"Keep as reference, write tests first"You'll adapt it. That's testing after. Delete means delete.
"Need to explore first"Fine. Throw away exploration, start with TDD.
"Test hard = design unclear"Listen to test. Hard to test = hard to use.
"TDD will slow me down"TDD IS the pragmatic path: catches bugs before commit, prevents regressions, lets you refactor without fear. "Pragmatic" shortcuts mean debugging in production — slower, not faster.
"Manual test faster"Manual doesn't prove edge cases. You'll re-test every change.
"Existing code has no tests"You're improving it. Add tests for existing code.

Red Flags - STOP and Start Over

  • Code before test
  • Test after implementation
  • Test passes immediately
  • Can't explain why test failed
  • Tests added "later"
  • Rationalizing "just this once"
  • "I already manually tested it"
  • "Tests after achieve the same purpose"
  • "It's about spirit not ritual"
  • "Keep as reference" or "adapt existing code"
  • "Already spent X hours, deleting is wasteful"
  • "TDD is dogmatic, I'm being pragmatic"
  • "This is different because..."

All of these mean: Delete code. Start over with TDD.

Example: Bug Fix

Bug: Empty email accepted

RED

test('rejects empty email', async () => {
  const result = await submitForm({ email: '' });
  expect(result.error).toBe('Email required');
});

Verify RED

$ npm test
FAIL: expected 'Email required', got undefined

GREEN

function submitForm(data: FormData) {
  if (!data.email?.trim()) {
    return { error: 'Email required' };
  }
  // ...
}

Verify GREEN

$ npm test
PASS

REFACTOR Extract validation for multiple fields if needed.

Verification Checklist

Before marking work complete:

  • Every new function/method has a test
  • Watched each test fail before implementing
  • Each test failed for expected reason (feature missing, not typo)
  • Wrote minimal code to pass each test
  • All tests pass
  • Output pristine (no errors, warnings)
  • Tests use real code (mocks only if unavoidable)
  • Edge cases and errors covered

Can't check all boxes? You skipped TDD. Start over.

When Stuck

ProblemSolution
Don't know how to testWrite wished-for API. Write assertion first. Ask your human partner.
Test too complicatedDesign too complicated. Simplify interface.
Must mock everythingCode too coupled. Use dependency injection.
Test setup hugeExtract helpers. Still complex? Simplify design.

Debugging Integration

Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.

Never fix bugs without a test.

Final Rule

Production code → test exists and failed first
Otherwise → not TDD

No exceptions without your human partner's permission.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

brainstorming

無料日本語概要

新しい機能や企画を作り始める前に、対話で目的や希望、制約を整理します。必要に応じて図や試作品で認識を確かめ、作業の規模に合った設計をまとめるスキルです。

  • 新機能の目的を明確にしたいとき
  • 講演や事業のアイデア整理
  • 画面や部屋の配置を見比べたいとき
obra/superpowers29.8万2026年10月10日 更新

diagnosing-superpowers

無料日本語概要

superpowersの作業記録を読み、作業の重複や計画逸脱、時間・トークン消費などを調べます。ファイルの行番号を根拠に、経緯を報告書へまとめるスキルです。

  • 作業の重複や計画逸脱を調べたいとき
  • セッションの時間や消費量の確認
  • スキルが使われたか確認したいとき
obra/superpowers29.8万2026年10月10日 更新

dispatching-parallel-agents

無料日本語概要

互いに依存しない不具合やテスト失敗を別々のエージェントに割り当て、並行して調査・修正するスキル。担当範囲を明確にし、結果の確認と変更の統合まで案内します。

  • 原因の異なるテスト失敗を調べたいとき
  • 別々の機能の不具合を修正したいとき
  • 複数エージェントの担当を整理したいとき
obra/superpowers29.8万2026年10月10日 更新

executing-plans

無料日本語概要

作成済みの実装計画を、同じセッションでタスクごとに実行します。テストの失敗と成功、進捗や判断を記録し、最後にブランチ全体をレビューするスキルです。

  • 作成済みの開発計画を実装したいとき
  • 実装用の別エージェントなしで進めたいとき
  • 進捗記録から作業を再開したいとき
obra/superpowers29.8万2026年10月10日 更新

finishing-a-development-branch

無料日本語概要

実装完了後に全テストを確認し、ローカルでのマージ、Pull Request作成、現状維持を選んで進めます。選択と作業環境に応じてブランチや作業領域を整理します。

  • 完成した機能をローカルでマージする
  • ブランチをpushしてPRを作る
  • 完成した変更を後で統合したいとき
obra/superpowers29.8万2026年10月10日 更新

receiving-code-review

無料日本語概要

コードレビューの指摘を実際のコードや対応環境と照らし合わせ、妥当性を確認します。不明点の整理、根拠を示した返答、修正ごとのテストまで進めるスキルです。

  • 曖昧なレビュー指摘を整理したいとき
  • 提案された変更の互換性確認
  • 追加機能が使われているか調べたいとき
obra/superpowers29.8万2026年10月10日 更新

obra のスキルをすべて見る

このスキルの問題を報告する