Write Integration Tests for an API
Create complete API integration tests with database setup, authentication, CRUD, and end-to-end scenarios.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Help me write integration tests for my REST API. Work from the framework, endpoints and test environment I specify below.
API framework: [e.g., Express, Fastify, NestJS or FastAPI]
Database: [e.g., PostgreSQL with Prisma or MongoDB with Mongoose]
Authentication: [e.g., a JWT bearer token, sessions or an API key]
Endpoints: [list the endpoints, e.g., POST /auth/login, GET /users/:id, POST /orders]
Test framework: [e.g., Jest with Supertest, Vitest or Mocha]
Test database: [e.g., a dedicated PostgreSQL database, in-memory SQLite or a mock]
CI service: [e.g., GitHub Actions or GitLab CI]
- Show the setup and teardown code. Configure the test database, seed fixtures and clean up between tests.
- Cover the authentication flow from login to token refresh, including invalid and expired tokens.
- Test create, read, update and delete operations across the endpoints. Assert successful responses, validation failures and HTTP error responses.
- Check that protected endpoints reject unauthenticated requests and that users can only perform the actions their permissions allow.
- Write one end-to-end user journey, such as signing up, logging in, creating a resource, editing it and deleting it.
- Add contract tests that compare the shape of each JSON response with the API documentation.
- Provide a GitHub Actions job that runs the suite with PostgreSQL as a service container.
Personalize this prompt with Léa · AI assistant
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
This prompt addresses integration tests in their most difficult dimension: managing database state between tests. The setup/teardown and seeding strategy is the key to a deterministic test suite that doesn't produce false positives due to residual data from a previous test. Authorization tests are often overlooked in integration test suites, yet they constitute the most critical security layer: verifying that protected endpoints are inaccessible without a valid token, and that permissions are correctly applied (a user cannot modify another's data). Requesting contract tests (JSON structure validation) is an advanced practice that prevents silent breaking changes in APIs: if a field is renamed or removed, the test fails immediately, alerting the team before the change reaches API consumers.
Use Cases
Expected Output
A complete integration test suite with setup/teardown, authentication tests, CRUD, authorization, and CI configuration.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
Be the first to comment on this prompt.
Glossary Terms
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Improve this prompt with the Optimizer
Analyze the prompt, strengthen the context and get a more precise version.
ChatGPT Prompts
Core techniques to guide ChatGPT more effectively.
AI prompts for web developers
Code review and debugging, keeping API keys and secrets out of the prompt.
Security, GDPR & Business Plans
ChatGPT Business, Claude Team, Gemini Workspace and Mistral Vibe compared from vendor sources: training, EU hosting and a GDPR checklist.
Similar Prompts
Task brief for Claude Code: frame a feature end to end
Brief template to delegate a complete feature to Claude Code: goal, starting point, constraints, definition of done, working rules and recap format.
Write a project's CLAUDE.md: the brief Claude Code reads at every session
Turns your project description into a dense CLAUDE.md: commands, structure, conventions, pitfalls, off-limits areas and situations where the agent must ask before acting.
Design a Secure Webhook API
Design a webhook API with event subscriptions, signed deliveries, retry limits, and a delivery log your support team can inspect.
Generate Storybook Stories for UI Components
Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.