testing-fundamentals
Auto-invoke when reviewing test files or discussing testing strategy. Enforces testing pyramid, strategic coverage, and stack-appropriate frameworks.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o testing-fundamentals.zip https://jpskill.com/download/18293.zip && unzip -o testing-fundamentals.zip && rm testing-fundamentals.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/18293.zip -OutFile "$d\testing-fundamentals.zip"; Expand-Archive "$d\testing-fundamentals.zip" -DestinationPath $d -Force; ri "$d\testing-fundamentals.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
testing-fundamentals.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
testing-fundamentalsフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
テストの基礎 復習
「テストできないものは理解できていないということだ。テストは理解の証である。」
適用するタイミング
このスキルは、以下の場合に有効化してください。
- テストファイル(.test.ts, .spec.ts, *.test.js)をレビューするとき
- ジュニアがテスト戦略について質問してきたとき
- テストなしで機能を完成させるとき
- カバレッジやテストの品質について議論するとき
テストピラミッド
▲
╱ ╲ E2E (10%)
╱ ╲ Playwright - 完全なユーザーフロー
╱─────╲
╱ ╲ 統合 (20%)
╱ ╲ Vitest + RTL - コンポーネントの相互作用
╱───────────╲
╱ ╲ ユニット (70%)
╱ ╲ Vitest - 関数、ユーティリティ、ロジック
─────────────────
- ユニットテスト (70%): 高速、独立、一つのことをテストする
- 統合テスト (20%): コンポーネントが連携して動作するかをテストする
- E2Eテスト (10%): 重要なユーザー体験のみをテストする
スタック固有のフレームワークガイド
| スタック | ユニット/統合 | E2E |
|---|---|---|
| Vite + React | Vitest + React Testing Library | Playwright |
| Create React App | Jest + RTL | Playwright |
| Next.js | Vitest または Jest + RTL | Playwright |
| Node.js | Vitest (ネイティブ ESM) | - |
| Python | pytest | - |
| Go | go test | - |
Vite に Vitest を使う理由
- ウォッチモードで Jest より 10~20 倍高速
- ネイティブ ESM サポート
- Vite と同じ設定 (vite.config.ts)
- Jest API と互換性がある
何をテストするか (3 つの質問)
- ハッピーパス: すべてがうまくいったときに動作するか?
- エッジケース: 空、null、最大値の場合にどうなるか?
- エラー状態: グレースフルに失敗するか?
良いテストのチェック項目:
- [ ] コンポーネントがクラッシュせずにレンダリングされる
- [ ] ユーザーインタラクションが動作する (クリック、タイプ、送信)
- [ ] エラー状態が正しく表示される
- [ ] ローディング状態が表示され、消える
- [ ] データがコンポーネントを正しく流れる
悪いテストのチェック項目:
- [ ] 実装の詳細 (内部状態、メソッド呼び出し)
- [ ] スタイリングまたは CSS クラス
- [ ] サードパーティライブラリの内部
- [ ] 大きなコンポーネントのスナップショットテスト (壊れやすい)
よくある間違い (アンチパターン)
1. 実装ではなく、振る舞いをテストする
// ❌ 悪い例: 内部状態をテストする
expect(component.state.isLoading).toBe(true);
// ✅ 良い例: ユーザーに見えるものをテストする
expect(screen.getByText('Loading...')).toBeInTheDocument();
2. 過剰なモック
// ❌ 悪い例: すべてをモックする
jest.mock('./utils');
jest.mock('./api');
jest.mock('./hooks');
// この時点で何をテストしているのか?
// ✅ 良い例: 外部境界のみをモックする
vi.mock('./api'); // API をモックし、残りをテストする
3. サードパーティライブラリをテストする
// ❌ 悪い例: React Query が動作することをテストする
expect(useQuery).toHaveBeenCalledWith('users');
// ✅ 良い例: 自分のコードの振る舞いをテストする
await waitFor(() => {
expect(screen.getByText('User Name')).toBeInTheDocument();
});
4. 壊れやすいセレクタ
// ❌ 悪い例: CSS を変更すると壊れる
screen.getByClassName('btn-primary-large-blue');
// ✅ 良い例: セマンティックで安定している
screen.getByRole('button', { name: 'Submit' });
5. すべてをテストする
// ❌ 悪い例: 100% のカバレッジ目標
// カバレッジのためだけに存在するテストになる
// ✅ 良い例: 戦略的なカバレッジ
// クリティカルパス、エッジケース、複雑なロジックをテストする
ソクラテス式質問
答えを与える代わりに、これらの質問をしてください。
- 戦略: 「テストが必要な最も重要なユーザーフローは何ですか?」
- カバレッジ: 「このテストがパスしても機能が壊れている場合、どうすればわかりますか?」
- エッジケース: 「どのような入力でこれが壊れる可能性がありますか? 空? Null? 10,000 個のアイテム?」
- 分離: 「あなたのコードとライブラリのコードのどちらをテストしていますか?」
- 価値: 「このテストは実際のバグを検出しますか?」
テスト構造 (AAA パターン)
describe('LoginForm', () => {
it('shows error when password is too short', async () => {
// Arrange
render(<LoginForm />);
// Act
await userEvent.type(screen.getByLabelText('Password'), '123');
await userEvent.click(screen.getByRole('button', { name: 'Login' }));
// Assert
expect(screen.getByText('Password must be at least 8 characters')).toBeInTheDocument();
});
});
指摘すべき危険信号
| フラグ | 質問 |
|---|---|
| 機能に対するテストがない | 「これが動作することを証明するテストは何ですか?」 |
| ハッピーパスのみテストされている | 「API が失敗したらどうなりますか? 入力が空の場合はどうなりますか?」 |
| すべてをモックしている | 「ここでは実際に何をテストしていますか?」 |
| 実装をテストしている | 「リファクタリングしても振る舞いが変わらなければ、このテストは壊れますか?」 |
| getByClassName の使用 | 「この要素を選択するよりセマンティックな方法はありますか?」 |
| 大きなスナップショットテスト | 「変更されたときに実際にこの差分を確認しますか?」 |
MCP の使用法
Context7 - フレームワークドキュメント
Fetch: Vitest ドキュメント
Fetch: React Testing Library クエリ
Fetch: Playwright ベストプラクティス
Octocode - 実際の例
Search: 人気のあるリポジトリで "vitest react testing library" を検索
Search: E2E パターンのために "playwright e2e test login" を検索
テストの命名規則
// パターン: it('should [期待される振る舞い] when [条件]')
it('should display error message when password is invalid')
it('should redirect to dashboard when login succeeds')
it('should disable submit button when form is submitting')
面接でのアピールポイント
「クリティカルなユーザーフローに焦点を当て、85% のカバレッジで包括的なテストを実装しました。ユニットテストには Vitest、コンポーネント統合テストには React Testing Library、ログイン、チェックアウト、支払いフローをカバーする E2E テストには Playwright を使用しました。」
テストは面接での話題になります。書くすべてのテストは、コードを理解している証拠です。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Testing Fundamentals Review
"If you can't test it, you don't understand it. Tests are proof of understanding."
When to Apply
Activate this skill when:
- Reviewing test files (.test.ts, .spec.ts, *.test.js)
- Junior asks about testing strategy
- Completing a feature without tests
- Discussing coverage or test quality
The Testing Pyramid
▲
╱ ╲ E2E (10%)
╱ ╲ Playwright - Full user flows
╱─────╲
╱ ╲ Integration (20%)
╱ ╲ Vitest + RTL - Component interactions
╱───────────╲
╱ ╲ Unit (70%)
╱ ╲ Vitest - Functions, utils, logic
─────────────────
- Unit Tests (70%): Fast, isolated, test one thing
- Integration Tests (20%): Components working together
- E2E Tests (10%): Critical user journeys only
Stack-Specific Framework Guide
| Stack | Unit/Integration | E2E |
|---|---|---|
| Vite + React | Vitest + React Testing Library | Playwright |
| Create React App | Jest + RTL | Playwright |
| Next.js | Vitest or Jest + RTL | Playwright |
| Node.js | Vitest (native ESM) | - |
| Python | pytest | - |
| Go | go test | - |
Why Vitest for Vite?
- 10-20x faster than Jest in watch mode
- Native ESM support
- Same config as Vite (vite.config.ts)
- Compatible with Jest API
What to Test (The 3 Questions)
- Happy Path: Does it work when everything goes right?
- Edge Cases: What happens with empty, null, max values?
- Error States: Does it fail gracefully?
Good Tests Check:
- [ ] Component renders without crashing
- [ ] User interactions work (click, type, submit)
- [ ] Error states display correctly
- [ ] Loading states appear and disappear
- [ ] Data flows correctly through the component
Bad Tests Check:
- [ ] Implementation details (internal state, method calls)
- [ ] Styling or CSS classes
- [ ] Third-party library internals
- [ ] Snapshot tests of large components (brittle)
Common Mistakes (Anti-Patterns)
1. Testing Implementation, Not Behavior
// ❌ BAD: Testing internal state
expect(component.state.isLoading).toBe(true);
// ✅ GOOD: Testing what user sees
expect(screen.getByText('Loading...')).toBeInTheDocument();
2. Over-Mocking
// ❌ BAD: Mock everything
jest.mock('./utils');
jest.mock('./api');
jest.mock('./hooks');
// What are you even testing at this point?
// ✅ GOOD: Mock only external boundaries
vi.mock('./api'); // Mock the API, test the rest
3. Testing Third-Party Libraries
// ❌ BAD: Testing that React Query works
expect(useQuery).toHaveBeenCalledWith('users');
// ✅ GOOD: Testing YOUR code's behavior
await waitFor(() => {
expect(screen.getByText('User Name')).toBeInTheDocument();
});
4. Brittle Selectors
// ❌ BAD: Breaks if you change CSS
screen.getByClassName('btn-primary-large-blue');
// ✅ GOOD: Semantic and stable
screen.getByRole('button', { name: 'Submit' });
5. Testing Everything
// ❌ BAD: 100% coverage goal
// Results in tests that exist just for coverage
// ✅ GOOD: Strategic coverage
// Test critical paths, edge cases, complex logic
Socratic Questions
Ask these instead of giving answers:
- Strategy: "What's the most critical user flow that needs testing?"
- Coverage: "If this test passes but the feature is broken, how would you know?"
- Edge Cases: "What inputs could break this? Empty? Null? 10,000 items?"
- Isolation: "Are you testing YOUR code or a library's code?"
- Value: "Would this test catch a real bug?"
Test Structure (AAA Pattern)
describe('LoginForm', () => {
it('shows error when password is too short', async () => {
// Arrange
render(<LoginForm />);
// Act
await userEvent.type(screen.getByLabelText('Password'), '123');
await userEvent.click(screen.getByRole('button', { name: 'Login' }));
// Assert
expect(screen.getByText('Password must be at least 8 characters')).toBeInTheDocument();
});
});
Red Flags to Call Out
| Flag | Question |
|---|---|
| No tests for feature | "What tests prove this works?" |
| Only happy path tested | "What if the API fails? What if input is empty?" |
| Mocking everything | "What are you actually testing here?" |
| Testing implementation | "Would this test break if you refactored but behavior stayed the same?" |
| getByClassName usage | "Is there a more semantic way to select this element?" |
| Large snapshot tests | "Will you actually review this diff when it changes?" |
MCP Usage
Context7 - Framework Docs
Fetch: Vitest documentation
Fetch: React Testing Library queries
Fetch: Playwright best practices
Octocode - Real Examples
Search: "vitest react testing library" in popular repos
Search: "playwright e2e test login" for E2E patterns
Test Naming Convention
// Pattern: it('should [expected behavior] when [condition]')
it('should display error message when password is invalid')
it('should redirect to dashboard when login succeeds')
it('should disable submit button when form is submitting')
Interview Gold
"I implemented comprehensive testing with 85% coverage focusing on critical user flows. I used Vitest for unit tests, React Testing Library for component integration tests, and Playwright for E2E tests covering login, checkout, and payment flows."
Tests are interview talking points. Every test you write is proof you understand the code.