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
Brand Comment Responses
Consistent and fast social media community management
Complete Code Review for Pull Requests
Get an exhaustive code review covering quality, performance, security, and maintainability for any language.
Master Advanced TypeScript Types
Strengthen your code's type safety with advanced generics, utility types, and discriminated unions.
Perplexity Prompt for Generating Python Code
Perplexity AI stands out from other AI assistants with its unique ability to combine real-time web search and code generation. When it comes to producing Python code, this advantage is significant: Perplexity can rely on the latest official documentation, current best practices, and up-to-date libraries to generate reliable and modern code. Unlike a classic LLM whose knowledge is frozen at a cutoff date, Perplexity verifies its sources in real time, drastically reducing the risk of obsolete code or deprecated functions. Whether you are a developer looking to speed up your workflow, a data scientist wanting to prototype quickly, or a beginner learning Python, a well-structured prompt turns Perplexity into a true development assistant. The key lies in the precision of your request: by specifying the technical context, constraints, and expected output format, you get production-ready code rather than a generic snippet. This guide offers optimized prompts to get the most out of Perplexity in your Python projects.