P
💻DeveloppementIntermediateAll AIs

Write Comprehensive Unit Tests

Generate an exhaustive unit test suite covering nominal cases, edge cases, and errors with appropriate mocks.

Paste in your AI

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

Tu es un expert en Test-Driven Development (TDD) et en assurance qualité logicielle. Je dois écrire des tests unitaires complets pour le code suivant écrit en [LANGAGE] avec le framework de test [EX: Jest, Pytest, JUnit] :

[COLLER_LE_CODE_À_TESTER]

Contexte :

  • Framework de test : [EX: Jest avec TypeScript, Pytest, JUnit 5]
  • Librairie de mock : [EX: jest.mock, unittest.mock, Mockito]
  • Couverture cible : [EX: 90% minimum]
  • Style de test : [EX: BDD avec describe/it, ou AAA (Arrange-Act-Assert)]

Génère une suite de tests complète qui couvre :

  1. Cas nominaux : les scénarios d'usage normal où tout fonctionne comme prévu.
  2. Cas limites : valeurs nulles, chaînes vides, tableaux vides, nombres négatifs, valeurs maximales.
  3. Cas d'erreur : exceptions attendues, erreurs réseau, timeouts, données malformées.
  4. Mocks et stubs : mock des dépendances externes (base de données, APIs, services tiers) avec des implémentations réalistes.
  5. Tests asynchrones : si le code est async, couvre les promesses résolues et rejetées.

Pour chaque test, utilise des noms descriptifs au format 'should [comportement attendu] when [condition]'. Inclus un commentaire expliquant pourquoi chaque cas limite est important à tester.

100% found this useful

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 is effective because it requests systematic coverage across the five most important test categories. By specifying the framework and mock library upfront, the AI produces directly usable code without requiring adaptation.</p><p>The imposed naming convention ('should [behavior] when [condition]') ensures self-documenting tests that also serve as living documentation of expected code behavior. This is an essential practice in team projects.</p><p>Requesting explanatory comments for edge cases transforms the tests into a pedagogical tool, helping less experienced developers understand why certain scenarios need testing, not just how.</p>

Use Cases

Writing tests for existing codeTDD trainingIncreasing code coverage

Expected Output

A complete unit test suite with nominal cases, edge cases, errors, mocks, and descriptive names ready to run.

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 maximiser l'efficacité, ajoute dans le prompt les valeurs exactes des cas limites (ex: `None, "", -1, 0, sys.maxsize`) et le chemin du module à mocker. Cela évite des tests génériques et assure des assertions précises.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Set up dependency vulnerability scanning

Automate dependency scanning

0219
💻DeveloppementIntermediateGemini

Gemini Prompt to Create a REST API

Creating a REST API is a fundamental skill in modern development, but it involves many architectural decisions: choice of framework, endpoint structure, authentication management, data validation, and documentation. Google Gemini excels at generating structured code and can guide you through each step of this process. Using a well-crafted prompt, you not only get the skeleton of your API but also best practices built in from the start: proper HTTP codes, centralized error handling, security middleware, and layered architecture. Whether you're building a microservice for a personal project or an enterprise API designed to handle thousands of requests, Gemini adapts its response to the requested complexity level. The main benefit is time savings during the scaffolding phase: instead of spending hours manually configuring each component, you get a solid, coherent foundation in seconds, which you can then customize to your specific business needs.

0170
💻DeveloppementIntermediateAll AIs

Automatically Generate Unit Tests with AI

Automatically generate an exhaustive unit test suite covering nominal cases, edge cases, and error cases for any source code.

0421
💻DeveloppementIntermediateAll AIs

Migrating from JavaScript to TypeScript

Gradually migrating a codebase to TypeScript

0169