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.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
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.
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
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.
Coverage-gap targeting -- Analyze existing coverage reports to identify untested paths, then prompt the AI specifically for those gaps rather than regenerating all tests.
Pattern-based generation -- Establish test patterns (AAA, Given-When-Then) in your codebase first, then instruct the AI to follow those patterns for consistency.
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.
Mutation-aware testing -- Use mutation testing results to identify weak test assertions and prompt the AI to strengthen them with more specific checks.
Human review gates -- Every AI-generated test must pass human review. AI excels at generating structure but can miss business logic nuances.
Prompt versioning -- Version your generation prompts alongside your code. When test patterns change, update prompts accordingly.
`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
this
buildUserPrompt
'unit'
return
expectedFormat
'typescript'
buildIntegrationTestPrompt
context
PromptContext
GenerationPrompt
const
`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
this
buildUserPrompt
'integration'
return
expectedFormat
'typescript'
buildE2ETestPrompt
context
PromptContext
GenerationPrompt
const
`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 least desktop and mobile viewports`
const
this
buildUserPrompt
'e2e'
return
expectedFormat
'typescript'
private
buildUserPrompt
context
PromptContext
testType
string
string
let
`Generate ${testType} tests for the following code:\n\n`
Provide the source code in every generation prompt -- AI agents cannot infer implementation details from function names alone. Always include the full source code being tested.
Include existing test patterns in context -- Show the agent 2-3 examples of your existing tests so it matches your project's style and conventions.
Generate tests incrementally, not all at once -- Generate tests for one file at a time, validate them, then move to the next. Batch generation without validation produces low-quality tests.
Use coverage reports to target generation -- Do not regenerate tests that already exist. Analyze coverage gaps and generate only for uncovered code paths.
Review AI-generated assertions carefully -- AI agents often generate assertions that are too loose (toBeDefined) or test implementation details rather than behavior.
Set up automated quality checks -- Run the quality checker on all generated tests before human review to catch common anti-patterns automatically.
Keep prompts under version control -- Store generation prompts in your repository so the entire team uses consistent prompts and changes are tracked.
Test the tests with mutation testing -- After generating tests, run mutation testing to verify the generated assertions actually detect bugs.
Establish a generation budget -- Set a maximum number of tokens or dollars per generation session to prevent runaway costs.
Document which tests are AI-generated -- Add a comment or metadata to generated tests so reviewers know to scrutinize them more carefully.
Anti-Patterns
Generating tests without source code context -- Prompting with only function signatures produces tests that compile but do not meaningfully verify behavior.
Accepting all generated tests without review -- AI-generated tests can have incorrect assertions, hardcoded values, and logic errors. Always review before committing.
Using temperature > 0 for test generation -- Non-deterministic generation produces inconsistent results. Use temperature 0 for reproducible test generation.
Generating tests for trivial code -- Do not waste tokens generating tests for simple getters, setters, or pass-through functions. Focus on complex logic.
Ignoring the quality checker output -- Automated quality checks catch 80% of common issues. Skipping them leads to low-quality tests entering the codebase.
Regenerating existing tests -- Before generating, check if tests already exist. Duplicate tests waste resources and create maintenance burden.
Using AI-generated tests as the sole quality gate -- AI-generated tests complement but do not replace human-written critical path tests.
Not validating that generated tests actually run -- A test that does not compile or throws at runtime provides zero value. Always execute generated tests before committing.
Generating E2E tests for unstable UIs -- If the UI is changing rapidly, generated E2E tests will break immediately. Wait for UI stabilization.
Trusting AI-generated mock implementations -- AI agents often create mocks that do not accurately represent the real dependency behavior. Verify mocks against actual service contracts.