test
npx machina-cli add skill AI-Driven-School/aiki/test --openclawFiles (1)
SKILL.md
4.1 KB
/test スキル
実装コードと要件定義からテストコードを自動生成します。
使用方法
/test
/test auth
/test --e2e
/test --unit
実行フロー
[1] 要件定義の読み込み
└─ docs/requirements/*.md(受入条件)
[2] 実装コードの確認
└─ src/**/*
[3] Codexに委譲
└─ codex exec "..." --full-auto
[4] テストファイル生成
└─ tests/**/*.spec.ts
Codex委譲コマンド
codex exec "
以下の受入条件を全てカバーするE2Eテストを生成してください。
【受入条件】
$(cat docs/requirements/{feature}.md | grep -A 100 '## 受入条件')
【テスト要件】
- Playwright使用
- 各受入条件に対応するテストケース
- Happy path + Edge case
- 適切なセレクタ(data-testid推奨)
- 日本語でテスト名を記述
【テンプレート】
import { test, expect } from '@playwright/test';
test.describe('{機能名}', () => {
test('{受入条件1}', async ({ page }) => {
// Arrange
// Act
// Assert
});
});
" --full-auto
生成されるテスト構成
tests/
├── {feature}.spec.ts # E2Eテスト
├── {feature}.unit.spec.ts # ユニットテスト(オプション)
└── fixtures/
└── {feature}.json # テストデータ
テストテンプレート
import { test, expect } from '@playwright/test';
test.describe('ユーザー認証', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/login');
});
test('メールとパスワードでログインできる', async ({ page }) => {
// Arrange
await page.fill('[data-testid="email-input"]', 'test@example.com');
await page.fill('[data-testid="password-input"]', 'password123');
// Act
await page.click('[data-testid="login-button"]');
// Assert
await expect(page).toHaveURL('/dashboard');
await expect(page.locator('[data-testid="welcome-message"]')).toBeVisible();
});
test('無効なパスワードでエラーが表示される', async ({ page }) => {
// Arrange
await page.fill('[data-testid="email-input"]', 'test@example.com');
await page.fill('[data-testid="password-input"]', 'wrong');
// Act
await page.click('[data-testid="login-button"]');
// Assert
await expect(page.locator('[data-testid="error-message"]')).toHaveText(
'メールアドレスまたはパスワードが正しくありません'
);
});
});
出力例
> /test auth
🧪 テストを生成します... (Codex)
要件定義を読み込み中...
✓ docs/requirements/auth.md(受入条件: 5件)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🚀 Codex (full-auto) でテスト生成中...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[Codex] tests/auth.spec.ts を作成中...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✅ テスト生成完了!
生成ファイル:
→ tests/auth.spec.ts
テストケース: 6件
✓ メールとパスワードでログインできる
✓ 認証成功時、ダッシュボードにリダイレクトされる
✓ 認証失敗時、エラーメッセージが表示される
✓ 空のフィールドでバリデーションエラー
✓ ログアウトでセッション終了
✓ セッション切れでログイン画面にリダイレクト
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
テスト実行: npx playwright test tests/auth.spec.ts
Source
git clone https://github.com/AI-Driven-School/aiki/blob/main/.claude/skills/test/SKILL.mdView on GitHub Overview
このスキルは、要件定義と実装コードからE2Eとユニットテストを自動生成します。Playwrightを用い、Codexへ委譲して受け入れ条件を網羅するテストを作成します。/test コマンドを使ってテスト作成と実行をサポートします。
How This Skill Works
実行は次の流れで行われます。まず docs/requirements/*.md を読み込み、次に src/**/* を確認します。続いて Codex に委譲して全受入条件をカバーするテストを生成させ、tests/**/*.spec.ts と fixtures/*.json に出力します。
When to Use It
- 受入条件ベースのE2E/ユニットテストを自動生成したい時
- 要件定義と実装コードの整合性を検証したい時
- Codexに委譲してテストを作成したい時
- テストファイル名やデータ fixtures を標準構成に従って生成したい時
- /test コマンドでテストを生成・実行したい時
Quick Start
- Step 1: /test [feature] を実行して要件を選択
- Step 2: Codex に委譲してテストを自動生成させる
- Step 3: 生成された tests/ のファイルを Playwright で実行して検証
Best Practices
- 受入条件を各テストケースに対応づける
- data-testid を活用したセレクタ設計を徹底する
- Happy path と Edge case の両方を含める
- テスト名は日本語で、テンプレートに沿って記述する
- tests/{feature}.spec.ts と fixtures/{feature}.json の構成を一貫して維持する
Example Use Cases
- ユーザー認証
- 商品検索とフィルタリング
- ダッシュボードの通知表示
- パスワードリセットと再設定
- カート操作と購入フロー
Frequently Asked Questions
Add this skill to your agents