20 of the best prompts for Claude for testing, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.
20 of the best prompts for Claude for testing, step by step across 4 stages. Works with ChatGPT, Claude, and Gemini.
Write tests that catch real bugs, build a reliable test suite, and ship code you can actually trust. This guide walks you through every stage of Claude for Testing, from Unit Tests all the way through Test Quality and Maintenance, with a curated, copy-ready prompt at each step. Each stage targets a specific phase of the process so you always know exactly what to ask and what output to expect. Works with ChatGPT, Claude, and Gemini and any other major AI tool.
Test individual functions and components in isolation.
Write unit tests
Write unit tests for this function using [JEST/VITEST/OTHER]: [PASTE FUNCTION]. Cover the happy path, edge cases, error conditions, and boundary values. Use descriptive test names.
Function hard
I have this function that is hard to test because it has side effects: [PASTE FUNCTION]. Refactor it to be testable and write the tests.
Write tests
Write tests for this React component: [PASTE COMPONENT]. Test: what renders initially, how it responds to user interaction, and how it handles loading and error states.
What should I
What should I actually test in this codebase? [DESCRIBE OR PASTE MODULE]. Identify the highest-value tests to write first vs what would be over-testing.
Tests are brittle
My tests are brittle — they break when I refactor even though the behavior is correct: [DESCRIBE TESTS]. Explain what is wrong and rewrite them to test behavior, not implementation.
Test how components and services work together.
Write integration test
Write an integration test for this API endpoint: [PASTE OR DESCRIBE ENDPOINT]. Test the happy path, validation errors, auth failure, and a database constraint violation.
Database integration tests
Set up database integration tests for [DESCRIBE APP AND DATABASE]. Show the test database config, setup/teardown hooks, and two example tests that use real data.
Write Playwright
Write a Playwright or Cypress end-to-end test for this user flow: [DESCRIBE FLOW, E.G. "USER SIGNS UP, VERIFIES EMAIL, AND COMPLETES ONBOARDING"]. Handle async steps and assertions correctly.
Integration tests are
My integration tests are slow. Here is the current setup: [DESCRIBE]. Suggest ways to speed them up without losing coverage — parallelisation, shared fixtures, smarter setup.
Test third-party API integrations
How do I test third-party API integrations without hitting the real API in tests? Show me the mocking strategy for [DESCRIBE API INTEGRATION] with examples.
Design a testing approach that balances coverage with maintenance cost.
Explain testing pyramid
Explain the testing pyramid for [DESCRIBE MY APP: FRONTEND SPA / API SERVICE / FULL-STACK]. How many unit, integration, and E2E tests should I have and why?
No tests
I have no tests and need to start. Here is my codebase: [DESCRIBE]. What should I test first to get the most protection per hour of work?
Test suite has %
My test suite has [N]% code coverage but I still have production bugs. What does coverage not tell me and what kinds of tests should I add?
Design test strategy
Design the test strategy for [DESCRIBE NEW FEATURE]. What unit tests, integration tests, and E2E tests do I need? What can I leave untested without taking on significant risk?
Should I use
Should I use [JEST / VITEST / TESTING LIBRARY / PLAYWRIGHT / CYPRESS] for [DESCRIBE PROJECT AND WHAT I NEED TO TEST]? Compare the options for my specific use case.
Keep your test suite fast, readable, and worth maintaining.
Review test file
Review this test file and tell me what is wrong with it: [PASTE TEST FILE]. Look for: testing implementation details, over-mocking, poor test names, and missing assertions.
Test duplication
I have a lot of test duplication. Here is a group of similar tests: [PASTE TESTS]. Refactor them to use shared fixtures or parameterised tests without losing clarity.
Mocks are getting
My mocks are getting out of hand: [DESCRIBE MOCK SETUP]. Show me a cleaner approach that is easier to maintain and less likely to give false positives.
Write test data factories
Write the test data factories for [DESCRIBE DOMAIN OBJECTS]. Each factory should produce valid objects with sensible defaults and allow any field to be overridden.
Run only the tests
How do I run only the tests related to the file I just changed, and how do I set up watch mode so tests run automatically as I edit?
Yes. Paste the function or component and Claude will write tests covering the happy path, edge cases, and error conditions with descriptive names using your preferred test framework.
Describe the API endpoint or service interaction and Claude will write integration tests with proper database setup, teardown, and assertions for success and error cases.
Yes. Describe your application and Claude will recommend the right balance of unit, integration, and E2E tests, what to test first in a legacy codebase, and how to get real coverage rather than just high percentages.
Unit test writing, test refactoring, test strategy design, database integration test setup, mocking strategies, and identifying what is actually worth testing are all strong areas.
Yes. Paste the brittle tests and Claude will explain whether they are testing implementation details instead of behavior, and rewrite them to be resilient to refactoring.
AI Prompts for Claude for DevOps
Automate deployments, write clean infrastructure code, debug pipelines faster, and build reliable systems..
See promptsAI Prompts for Claude for React
Build clean React components, design reusable hooks, fix bugs faster, and ship production-quality UI with confidence..
See promptsAI Prompts for Claude for Python
Write cleaner Python faster, debug stubborn errors, and level up your Python skills with Claude as your coding partner..
See prompts