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 :
- Setup et teardown : configuration de la base de données de test, seeding des fixtures nécessaires, nettoyage entre les tests.
- Authentification : tests du flux complet d'authentification (login, token invalide, token expiré, refresh).
- CRUD complet : tests de chaque endpoint avec cas de succès, validation des données invalides et gestion des erreurs HTTP.
- 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.
- 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).
- Tests de contrat : validation que la structure des réponses JSON est conforme à la documentation API.
- Configuration CI : job GitHub Actions pour exécuter les tests avec base de données PostgreSQL en service.
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
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.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Pour maximiser l'isolation, précisez dans le prompt l'utilisation d'une transaction rollback après chaque test plutôt qu'un nettoyage manuel — cela accélère l’exécution et évite les fuites de données. Ajoutez aussi un test de contrat avec un contrat OpenAPI pour valider automatiquement la structure des réponses.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Kubernetes Backup Strategy
Kubernetes Disaster Recovery Plan
Implement cost optimization with Terraform
Reduce cloud infrastructure costs
Debug Your Python Code with ChatGPT
A structured prompt to get a complete analysis of your Python bugs: identification, root cause explanation, commented fix, and prevention tips.
Implement input validation
Validate and sanitize inputs