testing-integration について
testing-integrationは、API、コンポーネント、データベース、サービス間のテストを書く開発者向けのガイダンススキルです。ルールやチェックリスト、例をまとめ、テスト手法の選択も案内します。
主な機能
- 01APIエンドポイントの統合テスト指針
- 02Reactコンポーネントの統合テストパターン
- 03データベーステストと分離の手法
- 04Pact契約テストとHypothesisのプロパティテスト
- 05境界でのZodスキーマ検証
活用シーン
- 01APIエンドポイントの統合テスト作成
- 02チーム間API契約の検証
- 03実際の依存関係を使ったDB層テスト
- 04新機能のテスト戦略立案
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ yonatangross/ orchestkit --skill testing-integrationインストール後、Claude Code で/testing-integrationを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
test-cases.jsonchecklists/contract-testing-checklist.mdproperty-testing-checklist.mdexamples/orchestkit-test-strategy.mdreferences/consumer-tests.mdork-delta.mdstrategies-guide.mdrules/_sections.mdemulate-stateful-testing.mdintegration-api.mdintegration-component.mdintegration-database.mdvalidation-zod-schema.mdverification-contract.mdverification-stateful.mdverification-techniques.mdscripts/create-integration-test.md詳細
統合テストとコントラクトテスト
API 境界、サービス間のコントラクト、コンポーネント統合、データベースレイヤー、プロパティベース検証、スキーマ検証をテストするための、目的に特化したパターンです。
クイックリファレンス
複雑な emulate のセットアップ(完全な設定生成、Webhook HMAC、CI でのワーカーごとのポート分離)については、
emulate-engineerサブエージェントに委任してください。emulate-seedスキルと組み合わせて使用します。
| 領域 | ルール/リファレンス | 影響 |
|---|---|---|
| ステートフル API テスト(emulate) | rules/emulate-stateful-testing.md | 高 |
| API エンドポイントテスト | rules/integration-api.md | 高 |
| React コンポーネント統合 | rules/integration-component.md | 高 |
| データベースレイヤーのテスト | rules/integration-database.md | 高 |
| Zod スキーマ検証 | rules/validation-zod-schema.md | 高 |
| Pact コントラクトテスト | rules/verification-contract.md | 中 |
| ステートフルテスト(Hypothesis) | rules/verification-stateful.md | 中 |
| エビデンスとプロパティベーステスト | rules/verification-techniques.md | 中 |
リファレンス
| トピック | ファイル |
|---|---|
| 上流で文書化されていない独自ルール | references/ork-delta.md |
| コンシューマー側の Pact テスト | references/consumer-tests.md |
| Hypothesis ストラテジーガイド | references/strategies-guide.md |
チェックリスト
| チェックリスト | ファイル |
|---|---|
| コントラクトテストの準備状況 | checklists/contract-testing-checklist.md |
| プロパティベーステスト | checklists/property-testing-checklist.md |
スクリプトとテンプレート
| スクリプト | ファイル |
|---|---|
| 統合テストの作成 | scripts/create-integration-test.md |
例
| 例 | ファイル |
|---|---|
| テスト戦略の全体像 | examples/orchestkit-test-strategy.md |
上流の対象範囲(ここでは繰り返さないでください)
このスキルは Pact、Pact Broker、FastAPI のテストを扱います。ここに含まれるのは OrchestKit 独自の差分のみです。以下のトピックについては、ここで説明を繰り返すのではなく、ベンダーのドキュメントを参照してください。
これらのトピックのうち、OrchestKit 独自の対象範囲は引き続きこのスキルに含まれ、外部には委ねません。
rules/verification-contract.md には、ork が必須とする Broker コマンド 2 つとセレクターのデフォルトが記載されています。
checklists/contract-testing-checklist.md には CI/CD、分離、セキュリティのチェック項目が記載されています。references/consumer-tests.md には、ビジネス用語を使ったプロバイダー状態の命名規則とマッチャーの表が記載されています。上流に参照先のないルールは references/ork-delta.md に記載されています。
ステートフル API テスト(emulate — 第一候補)
GitHub、Vercel、Google API の統合テストでは、emulate を第一候補とします。静的なモックではなく、実際の API の動作をモデル化する完全なステートマシンを提供します。
| ツール | 最適な用途 |
|---|---|
| emulate | ステートフル API テスト(GitHub/Vercel/Google) — 第一候補 |
| Pact | チーム間のコントラクト検証 |
| MSW | フロントエンドの HTTP モック(単純なリクエスト/レスポンス) |
| Nock | Node.js のユニットレベル HTTP インターセプト |
完全な判断マトリックス、seed-start-test-assert パターン、誤った例と正しい例については rules/emulate-stateful-testing.md を参照してください。
Testcontainers(CI で実際の依存関係を使用)
コントラクトテストや emulate だけでは不十分な場合(たとえば、実際の Postgres、Redis、Kafka、または S3 互換ストアに対するテスト)には、Testcontainers がテストごとに一時的な Docker コンテナーを起動し、テスト後に破棄します。上記の path_patterns はすでに **/testcontainers/** に一致するため、そこでこれらのパターンを使用してください。
対象:testcontainers >= 11.0.0(Node)。v11(2026 年第 1 四半期)では、名前付きネットワークの自動クリーンアップ、.withReuse() によるコンテナーの再利用、Podman の正式サポートが追加されました。
Node.js(testcontainers-node)
import { PostgreSqlContainer } from '@testcontainers/postgresql'
import { describe, beforeAll, afterAll, test, expect } from 'vitest'
describe('UserRepository integration', () => {
let container: Awaited<ReturnType<PostgreSqlContainer['start']>>
let repo: UserRepository
beforeAll(async () => {
container = await new PostgreSqlContainer('postgres:16-alpine')
.withDatabase('test')
.withUsername('test')
.withPassword('test')
.withReuse() // v11+ — reuse across runs to speed CI
.start()
repo = new UserRepository(container.getConnectionUri())
await repo.migrate()
}, 30_000)
afterAll(async () => {
await container.stop()
})
test('persists and retrieves a user', async () => {
const created = await repo.create({ email: '[email protected]' })
const found = await repo.findById(created.id)
expect(found?.email).toBe('[email protected]')
})
})
Python(testcontainers-python)
from testcontainers.postgres import PostgresContainer
import pytest
@pytest.fixture(scope="session")
def postgres():
with PostgresContainer("postgres:16-alpine") as pg:
yield pg.get_connection_url()
def test_user_repo(postgres):
repo = UserRepository(postgres)
repo.migrate()
user = repo.create(email="[email protected]")
assert repo.find_by_id(user.id).email == "[email protected]"
判断マトリックス:
| シナリオ | 選択肢 |
|---|---|
| サードパーティ API(GitHub、Vercel、Google) | emulate |
| チーム間の API コントラクト | Pact |
| 実際の Postgres/Redis/Kafka との統合 | Testcontainers |
| フロントエンドのテストで HTTP をモックするだけ | MSW |
クイックスタート:API 統合テスト
TypeScript(Supertest)
import request from 'supertest';
import { app } from '../app';
describe('POST /api/users', () => {
test('creates user and returns 201', async () => {
const response = await request(app)
.post('/api/users')
.send({ email: '[email protected]', name: 'Test' });
expect(response.status).toBe(201);
expect(response.body.id).toBeDefined();
expect(response.body.email).toBe('[email protected]');
});
test('returns 400 for invalid email', async () => {
const response = await request(app)
.post('/api/users')
.send({ email: 'invalid', name: 'Test' });
expect(response.status).toBe(400);
expect(response.body.error).toContain('email');
});
});
Python(FastAPI + httpx)
import pytest
from httpx import ASGITransport, AsyncClient
from app.main import app
@pytest.fixture
async def client():
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
yield ac
@pytest.mark.asyncio
async def test_create_user(client: AsyncClient):
response = await client.post(
"/api/users",
json={"email": "[email protected]", "name": "Test"}
)
assert response.status_code == 201
assert response.json()["email"] == "[email protected]"
カバレッジ目標
| 領域 | 目標 |
|---|---|
| API エンドポイント | 70% 以上 |
| サービスレイヤー | 80% 以上 |
| コンポーネント間の連携 | 70% 以上 |
| コントラクトテスト | コンシューマーが使用するすべてのエンドポイント |
| プロパティテスト | すべてのエンコード/デコード関数、および冪等関数 |
主な原則
- 境界でテストする -- API 入力、データベースクエリ、サービス呼び出し、外部連携
- テストごとに状態を新しくする -- インメモリデータベース、トランザクションのロールバック、共有の可変状態を避ける
- コントラクトではマッチャーを使う -- 完全一致の値の代わりに
Like()、EachLike()、Term()を使う - 不変条件にはプロパティベーステストを使う -- 往復、冪等性、可換性のプロパティ
- 境界でスキーマを検証する -- すべての API 境界で Zod の
.safeParse()を使う - 根拠に基づいて完了を確認する -- 終了コード 0、カバレッジレポート、タイムスタンプ
このスキルを使う場面
- API エンドポイントテストの作成(Supertest、httpx)
- プロバイダーを使った React コンポーネントの統合テストの設定
- 分離されたデータベース統合テストの作成
- Pact のコンシューマー/プロバイダーコントラクトテストの実装
- Hypothesis を使ったプロパティベーステストの追加
- API 境界での Zod スキーマの検証
- 新しい機能やサービスのテスト戦略の策定
関連スキル
ork:testing-unit— 単体テストのパターン、フィクスチャ、モックork:testing-e2e— エンドツーエンドの Playwright テストork:emulate-seed— エミュレートプロバイダー用のシード設定の作成ork:database-patterns— データベーススキーマとマイグレーションのパターンork:api-design— エンドポイントテスト向けの API 設計パターン