Write integration tests for an API
Create comprehensive 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 testing in its 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 user's data).</p><p>The request for contract tests (JSON structure validation) is an advanced practice that prevents silent breaking changes in APIs: if a field is renamed or deleted, the test fails immediately, alerting the team before the change reaches API clients.</p>
Use Cases
Expected Output
Complete integration test suite with setup/teardown, authentication tests, CRUD, permissions and CI configuration.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt GuideGlossary Terms
Similar Prompts
Learn the basics of Git for beginners
Learn Git from scratch with illustrated explanations, concrete examples, a practical workflow and a cheatsheet of essential commands.
Define a Git strategy for a team
Define a comprehensive Git strategy adapted to your team: branching model, conventions, code review and release management.
Configure a CI/CD pipeline with GitHub Actions
Configure a professional CI/CD pipeline with GitHub Actions covering testing, security, Docker build and multi-environment deployment.
Create an optimized Dockerfile for production
Create an optimized multi-stage Dockerfile for production with maximum security, lightweight image and best practices.