Skip to content
Back to skills

Collection

ASecurity

E2Eテストのためのテストデータ管理戦略。 📚 リソース参照: このスキルには以下のリソースが含まれています。 必要に応じて該当するリソースを参照してください: - `.claude/skills/test-data-management/resources/cleanup-patterns.md`: Cleanup Patternsリソース - `.claude/skills/test-data-management/resources/data-isolation-techniques.md`: Data Isolation Techniquesリソース - `.claude/skills/test-data-management/resources/seeding-strategies.md`: Seeding Strategiesリソース - `.claude/skills/test-data-management/templates/fixture-template.ts`: Fixtureテンプレート - `.claude/skills/test-data-...

  • 24 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 8, 2026
testingtypescriptgotestingapidatabase

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add mattnigh/skills_collection --skill collection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattnigh-collection-a43ec39b/badge)](https://www.skillsdirectory.com/skills/mattnigh-collection-a43ec39b)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: .claude/skills/test-data-management/SKILL.md
description: |
  E2Eテストのためのテストデータ管理戦略。

  📚 リソース参照:
  このスキルには以下のリソースが含まれています。
  必要に応じて該当するリソースを参照してください:

  - `.claude/skills/test-data-management/resources/cleanup-patterns.md`: Cleanup Patternsリソース
  - `.claude/skills/test-data-management/resources/data-isolation-techniques.md`: Data Isolation Techniquesリソース
  - `.claude/skills/test-data-management/resources/seeding-strategies.md`: Seeding Strategiesリソース

  - `.claude/skills/test-data-management/templates/fixture-template.ts`: Fixtureテンプレート

  - `.claude/skills/test-data-management/scripts/generate-test-data.mjs`: Generate Test Dataスクリプト

version: 1.0.0
---

# Test Data Management Skill

## 概要

E2E テストのためのテストデータ管理戦略。Seeding(データ準備)、Teardown(クリーンアップ)、データ分離技術を提供。

## 核心概念

### 1. Seeding(データ準備)戦略

**目的**: テスト実行前に必要なデータを準備

```typescript
// APIによるSeeding
test.beforeEach(async ({ request }) => {
  await request.post("/api/users", {
    data: { name: "Test User", email: "test@example.com" },
  });
});

// Fixtureファイル使用
import testData from "./fixtures/users.json";

test.beforeEach(async ({ request }) => {
  for (const user of testData) {
    await request.post("/api/users", { data: user });
  }
});
```

### 2. Teardown(クリーンアップ)戦略

**目的**: テスト実行後にデータを削除

```typescript
test.afterEach(async ({ request }) => {
  // テストデータ削除
  await request.delete("/api/users/test@example.com");
});

// データベース直接クリーンアップ
test.afterEach(async () => {
  await db.query('DELETE FROM users WHERE email LIKE "test-%"');
});
```

### 3. テストデータ分離

**並列実行時のデータ競合回避**:

```typescript
test("ユーザー作成", async ({ page }) => {
  // 一意なデータ生成
  const uniqueEmail = `user-${Date.now()}@example.com`;
  const uniqueId = crypto.randomUUID();

  await page.goto("/register");
  await page.getByLabel("Email").fill(uniqueEmail);
  // ...
});
```

## 実装パターン

### パターン 1: Fixture-based パターン

```typescript
// fixtures/test-user.ts
export const test = base.extend({
  testUser: async ({ request }, use) => {
    // Setup
    const user = {
      name: "Test User",
      email: `test-${Date.now()}@example.com`,
    };
    const response = await request.post("/api/users", { data: user });
    const createdUser = await response.json();

    // テストに渡す
    await use(createdUser);

    // Cleanup
    await request.delete(`/api/users/${createdUser.id}`);
  },
});

// テスト使用
test("ユーザープロフィール表示", async ({ page, testUser }) => {
  await page.goto(`/users/${testUser.id}`);
  await expect(page.getByText(testUser.name)).toBeVisible();
});
```

### パターン 2: Database Seeding

```typescript
// setup/seed-database.ts
import { PrismaClient } from "@prisma/client";

export async function seedDatabase() {
  const prisma = new PrismaClient();

  await prisma.user.createMany({
    data: [
      { name: "User 1", email: "user1@test.com" },
      { name: "User 2", email: "user2@test.com" },
    ],
  });

  await prisma.$disconnect();
}

// tests/users.spec.ts
test.beforeAll(async () => {
  await seedDatabase();
});

test.afterAll(async () => {
  const prisma = new PrismaClient();
  await prisma.user.deleteMany({ where: { email: { endsWith: "@test.com" } } });
  await prisma.$disconnect();
});
```

### パターン 3: トランザクションベース

```typescript
test.describe("トランザクション使用", () => {
  let transactionId;

  test.beforeEach(async ({ request }) => {
    // トランザクション開始
    const response = await request.post("/api/transactions/begin");
    transactionId = (await response.json()).id;
  });

  test.afterEach(async ({ request }) => {
    // ロールバック
    await request.post(`/api/transactions/${transactionId}/rollback`);
  });

  test("データ作成テスト", async ({ page }) => {
    // トランザクション内でデータ操作
    // ...
  });
});
```

## ベストプラクティス

### DO(推奨)

1. **一意なテストデータ生成**:

```typescript
const email = `test-${crypto.randomUUID()}@example.com`;
const timestamp = Date.now();
```

2. **最小限のデータセット**:

```typescript
// ✅ 必要最小限
await createUser({ name: "Test", email: "test@example.com" });

// ❌ 過剰なデータ
await create100Users(); // 不要
```

3. **クリーンアップの確実な実行**:

```typescript
test.afterEach(async () => {
  // 必ずクリーンアップ
});
```

### DON'T(非推奨)

1. **固定データへの依存を避ける**:

```typescript
// ❌ 固定データ(他テストと競合)
await page.fill('[name="email"]', "fixed@example.com");

// ✅ 動的データ
await page.fill('[name="email"]', `test-${Date.now()}@example.com`);
```

2. **グローバルステートを避ける**:

```typescript
// ❌
let globalUser; // 避けるべき

// ✅
test.beforeEach(async ({ }, testInfo) => {
  const user = { ... }; // テストスコープ内
});
```

## リソース

- [resources/seeding-strategies.md](resources/seeding-strategies.md) - Seeding 戦略詳細(API、DB、Fixture)
- [resources/cleanup-patterns.md](resources/cleanup-patterns.md) - クリーンアップパターンとベストプラクティス
- [resources/data-isolation-techniques.md](resources/data-isolation-techniques.md) - 並列実行時のデータ分離技術
- [scripts/generate-test-data.mjs](scripts/generate-test-data.mjs) - テストデータ生成スクリプト
- [templates/fixture-template.ts](templates/fixture-template.ts) - Playwright の fixture 拡張テンプレート

## 関連スキル

- **.claude/skills/playwright-testing/SKILL.md** (`.claude/skills/playwright-testing/SKILL.md`): Playwright の基本操作
- **.claude/skills/flaky-test-prevention/SKILL.md** (`.claude/skills/flaky-test-prevention/SKILL.md`): テスト安定化
- **.claude/skills/api-mocking/SKILL.md** (`.claude/skills/api-mocking/SKILL.md`): API モック

Files in this skill

  • 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md15.1 KB
  • 17hz__nextjs-template__claude__skills__example-skill__SKILL.md316 B
  • 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md3.5 KB
  • 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md5.4 KB
  • 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md7.7 KB
  • 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md26.1 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md15.7 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md17.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md9.4 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md12.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md16.6 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md11.2 KB
  • 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md14.8 KB
  • 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md16.2 KB
  • 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md11.8 KB
  • 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md17.5 KB
  • 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md19.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md6.2 KB
  • 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md18.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md24.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in testing →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.