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
Answer 3 questions and Léa tailors the prompt to your situation.
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
Convert CSS to Tailwind
Migrate styling to Tailwind
Refactor legacy code to modern patterns
Gradually modernizing legacy code
Gemini Prompt for Generating SQL Queries
Gemini, Google's artificial intelligence model, excels at generating SQL queries through its deep understanding of data structures and database syntax. Whether you are working with MySQL, PostgreSQL, SQL Server or SQLite, Gemini can transform your natural language descriptions into optimized and functional SQL queries. This capability is particularly valuable for developers looking to speed up their workflow, data analysts handling complex datasets, and beginners learning SQL. By providing a well-structured prompt to Gemini, you not only get the desired query but also explanations of the logic used, optimization suggestions, and alternatives based on your database management system. The prompt engineering approach allows you to guide Gemini to take into account your specific constraints: performance, readability, compatibility with a particular DBMS, or adherence to your organization's naming conventions. Discover how to formulate your prompts to get the most out of Gemini in generating SQL queries.
Implement secrets management
Secure credentials management