P
💻DeveloppementIntermediateAll AIs

Generate Mocks and Fixtures for Your Automated Tests

A prompt to automatically generate realistic mocks, stubs and data fixtures adapted to your test framework and use cases.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un ingénieur qualité logicielle spécialisé en testing. Génère des mocks et fixtures complets pour le contexte suivant :

Langage / Framework de test : [LANGAGE_ET_FRAMEWORK] (ex : Python/pytest, JavaScript/Jest, TypeScript/Vitest, Java/JUnit)
Entités ou modules à mocker : [ENTITES_A_MOCKER] (ex : service d'authentification, API de paiement Stripe, base de données PostgreSQL, service d'envoi d'emails)
Cas de test visés : [CAS_DE_TEST] (ex : succès standard, erreur réseau, timeout, données invalides, réponse vide)

Pour chaque entité, fournis :

  1. Fixtures de données : des jeux de données réalistes (pas de "foo/bar") couvrant les cas nominaux et les cas limites. Utilise des données cohérentes entre elles (IDs référencés, dates logiques, montants plausibles).
  2. Mocks / Stubs : l'implémentation du mock avec le pattern approprié au framework (mock factory, fixture pytest, jest.fn(), vi.fn(), etc.). Inclus le typage si le langage le supporte.
  3. Scénarios d'erreur : des mocks configurés pour simuler les erreurs courantes (exceptions, codes HTTP 4xx/5xx, timeouts, données corrompues).
  4. Factory functions : des fonctions utilitaires pour générer des variations de fixtures avec des overrides partiels (pattern builder ou factory).
  5. Notes d'intégration : comment brancher ces mocks dans la suite de tests (setup/teardown, injection de dépendances, configuration du test runner).

Respecte ces contraintes :

  • Code prêt à copier-coller, avec imports nécessaires
  • Nommage clair et conventions du framework
  • Commentaires expliquant les choix de données
  • Séparation fixtures / mocks dans des fichiers dédiés si c'est la convention du framework

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 lets you quickly produce all the test infrastructure your projects need: data fixtures, external service mocks and generation factories. By specifying your <strong>language and test framework</strong>, the AI automatically adapts patterns (pytest fixtures, Jest mocks, Vitest spies, etc.) and naming conventions.</p><p>The key to a good result is describing precisely the <strong>entities to mock</strong>: do not just say "the API", but specify "the Stripe API with charge.create and refund.create endpoints". The more specific you are about the <strong>target test cases</strong>, the more the fixtures will cover your real needs, including often-forgotten edge cases like timeouts or partial responses.</p><p>The generated factory functions prevent data duplication between tests. They follow the <strong>builder/factory pattern</strong> which allows creating variants by overriding only the fields relevant to each test, keeping your tests readable and maintainable.</p>

Use Cases

Bootstrap tests for a new microservice with third-party API mocksCreate realistic fixtures for a test databaseSimulate network error scenarios to test application resilienceGenerate data factories for complex integration tests

Expected Output

Ready-to-use code containing fixture files with realistic data, typed mocks for each external service, factory functions with partial overrides, and configured error scenarios — all adapted to the specified test framework.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Pour des données plus réalistes sans les coder en dur, ajoutez dans le prompt l’instruction d’utiliser une librairie comme Faker (Python) ou faker.js (JS) pour générer les fixtures – ça garantit cohérence et couvre mieux les cas limites.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementAdvancedClaude

Configure a CI/CD Pipeline with GitHub Actions

Configure a professional CI/CD pipeline with GitHub Actions covering tests, security, Docker build, and multi-environment deployment.

45602
💻DeveloppementIntermediateAll AIs

Perplexity Prompt to Create a Chatbot

Perplexity stands out from other AI assistants due to its ability to search and synthesize information from the web in real time. To create a chatbot, this feature is invaluable: Perplexity can identify the latest frameworks, compare current technical solutions, and provide recommendations based on the state of the art. Whether you want to develop a customer support chatbot, an internal conversational assistant, or a specialized domain bot, Perplexity guides you through architectural choices, available APIs, and implementation best practices. By combining documented research with code generation, it enables you to quickly move from concept to functional prototype, while relying on verifiable sources for every technical recommendation.

0286
💻DeveloppementIntermediateAll AIs

Complete GitHub Actions Pipeline

Create a complete CI/CD pipeline

0280
💻DeveloppementBeginnerAll AIs

Implement input validation

Validate and sanitize inputs

0308