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.
Tu es un expert en assurance qualité logicielle spécialisé dans les tests d'intégration d'APIs. Je dois créer une suite de tests d'intégration complète pour mon API. **API à tester :** - Framework : [EX: Express, Fastify, NestJS, FastAPI] - Base de données : [EX: PostgreSQL avec Prisma, MongoDB avec Mongoose] - Authentification : [EX: JWT Bearer token, sessions, API key] - Endpoints principaux : [LISTER_LES_ENDPOINTS: ex. POST /auth/login, GET /users/:id, POST /orders] **Stack de test :** - Framework de test : [EX: Jest avec Supertest, Vitest, Mocha] - Base de données de test : [EX: base PostgreSQL dédiée, SQLite en mémoire, mock] - CI : [EX: GitHub Actions, GitLab CI] Crée une suite de tests d'intégration professionnelle incluant : 1. **Setup et teardown** : configuration de la base de données de test, seeding des fixtures nécessaires, nettoyage entre les tests. 2. **Authentification** : tests du flux complet d'authentification (login, token invalide, token expiré, refresh). 3. **CRUD complet** : tests de chaque endpoint avec cas de succès, validation des données invalides et gestion des erreurs HTTP. 4. **Autorisations** : tests que les endpoints protégés rejettent les requêtes non authentifiées et que les règles de permission sont respectées. 5. **Scénarios end-to-end** : un scénario complet simulant un parcours utilisateur réel (ex: créer un compte → se connecter → créer une ressource → la modifier → la supprimer). 6. **Tests de contrat** : validation que la structure des réponses JSON est conforme à la documentation API. 7. **Configuration CI** : job GitHub Actions pour exécuter les tests avec base de données PostgreSQL en service.
Why this prompt works
<p>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.</p><p>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).</p><p>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.</p>
Use Cases
Expected Output
A complete integration test suite with setup/teardown, authentication tests, CRUD, authorization, and CI configuration.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt Guide📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Similar Prompts
Automate Your Git Commits with AI
This prompt analyzes a Git diff and automatically generates structured commit messages following project conventions, with atomic splitting if needed.
Define a Git Strategy for a Team
Define a complete Git strategy adapted to your team: branching model, conventions, code review, and release management.
Implement Clean Architecture in Practice
Implement Clean Architecture in practice with layers, ports and adapters, use cases, and unit tests without infrastructure.
Legacy Code Refactoring
Safely and incrementally refactor legacy code following SOLID principles and modern best practices.