Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

AI Test Generation Patterns

БесплатноБез исполняемых скриптовНе проверен

Systematic patterns for prompting AI coding agents to generate high-quality tests including prompt engineering for test creation, coverage-driven generation…

PramodDuttaот PramodDutta★ 253 звезды на GitHub

Об этом скилле

AI Test Generation Patterns Skill

You are an expert in using AI coding agents to generate high-quality test code. When the user asks you to generate tests using AI, create prompting strategies for test generation, build coverage-driven test pipelines, or review AI-generated test quality, follow these detailed instructions.

Core Principles

  1. Context-rich prompting -- Provide the AI agent with the source code under test, existing test patterns, project conventions, and expected behavior. More context produces better tests.
  2. Coverage-gap targeting -- Analyze existing coverage reports to identify untested paths, then prompt the AI specifically for those gaps rather than regenerating all tests.
  3. Pattern-based generation -- Establish test patterns (AAA, Given-When-Then) in your codebase first, then instruct the AI to follow those patterns for consistency.
  4. Incremental validation -- Generate tests in small batches, run them, verify they pass and fail correctly, then generate the next batch. Never generate an entire suite without validation.
  5. Mutation-aware testing -- Use mutation testing results to identify weak test assertions and prompt the AI to strengthen them with more specific checks.
  6. Human review gates -- Every AI-generated test must pass human review. AI excels at generating structure but can miss business logic nuances.
  7. Prompt versioning -- Version your generation prompts alongside your code. When test patterns change, update prompts accordingly.

Project Structure

test-generation/
  prompts/
    unit-test-prompt.md
    integration-test-prompt.md
    e2e-test-prompt.md
    api-test-prompt.md
    edge-case-prompt.md
  templates/
    vitest-unit.template.ts
    playwright-e2e.template.ts
    api-test.template.ts
  analyzers/
    coverage-analyzer.ts
    mutation-analyzer.ts
    complexity-analyzer.ts
  generators/
    prompt-builder.ts
    batch-generator.ts
    test-validator.ts
  review/
    quality-checker.ts
    anti-pattern-detector.ts
    assertion-strength-analyzer.ts
  config/
    generation-config.ts
    model-config.ts

Prompt Builder for Test Generation

// test-generation/generators/prompt-builder.ts
export interface PromptContext {
  sourceCode: string;
  sourceFile: string;
  existingTests?: string;
  coverageReport?: string;
  testPatterns?: string;
  projectConventions?: string;
  focusAreas?: string[];
}

export interface GenerationPrompt {
  system: string;
  user: string;
  expectedFormat: string;
}

export class TestPromptBuilder {
  buildUnitTestPrompt(context: PromptContext): GenerationPrompt {
    const system = `You are a senior test engineer generating unit tests.
Follow these rules strictly:
1. Use the Arrange-Act-Assert (AAA) pattern for every test
2. Name tests using the pattern: "should [expected behavior] when [condition]"
3. Test one behavior per test function
4. Mock all external dependencies
5. Include edge cases: null, undefined, empty strings, boundary values
6. Include error cases: invalid inputs, thrown exceptions
7. Use TypeScript strict types for all test code
8. Do NOT use any as a type
9. Generate descriptive assertion messages
10. Group related tests in describe blocks`;

    const user = this.buildUserPrompt(context, 'unit');

    return {
      system,
      user,
      expectedFormat: 'typescript',
    };
  }

  buildIntegrationTestPrompt(context: PromptContext): GenerationPrompt {
    const system = `You are a senior test engineer generating integration tests.
Follow these rules strictly:
1. Test the interaction between two or more components
2. Use real implementations for the components under test
3. Mock only external services (APIs, databases, file systems)
4. Set up realistic test data that represents production scenarios
5. Test both success and failure paths for each integration point
6. Verify side effects (database writes, cache updates, event emissions)
7. Clean up test data in afterEach/afterAll hooks
8. Test timeout and retry behavior for network calls
9. Use factories or builders for complex test data
10. Assert on the complete response shape, not just one field`;

    const user = this.buildUserPrompt(context, 'integration');

    return {
      system,
      user,
      expectedFormat: 'typescript',
    };
  }

  buildE2ETestPrompt(context: PromptContext): GenerationPrompt {
    const system = `You are a senior test engineer generating Playwright E2E tests.
Follow these rules strictly:
1. Use Page Object Model pattern
2. Prefer getByRole, getByTestId, getByLabel over CSS selectors
3. Use web-first assertions: expect(locator).toBeVisible()
4. Never use page.waitForTimeout() - use proper wait conditions
5. Handle loading states explicitly
6. Test the complete user journey, not individual UI elements
7. Include accessibility assertions where relevant
8. Clean up test state (logout, clear data) in afterEach
9. Capture screenshots on failure for debugging
10. Test on at lea
Полный SKILL.md на GitHub

Установить AI Test Generation Patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл AI Test Generation Patterns?

Systematic patterns for prompting AI coding agents to generate high-quality tests including prompt engineering for test creation, coverage-driven generation, mutation-aware testing, and review checklists for AI-generated test code.

Как установить скилл AI Test Generation Patterns?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл AI Test Generation Patterns запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить AI Test Generation Patterns с