P
IntermediateAll AIs

Write Comprehensive Unit Tests for a Function

Generates a comprehensive unit test suite following the AAA pattern, covering all nominal, edge and error scenarios for a given function.

Paste in your AI

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

Tu es un expert en qualité logicielle et TDD. Génère une suite de tests unitaires exhaustive pour le code suivant.

Langage / Framework de test : [LANGAGE_FRAMEWORK_TEST] (ex: Jest, pytest, JUnit)

Code à tester :

[CODE_A_TESTER]

Contexte métier : [CONTEXTE_METIER]

Pour chaque test :

  • Utilise la convention de nommage : should_[comportement]_when_[condition]
  • Respecte le pattern AAA (Arrange, Act, Assert)
  • Ajoute un commentaire expliquant le cas testé

Couvre obligatoirement :

  1. Cas nominaux (happy path) — au moins 3 scénarios
  2. Cas limites (valeurs nulles, vides, extrêmes)
  3. Cas d'erreur et exceptions attendues
  4. Comportements aux frontières (boundary testing)
  5. Si applicable : mocks/stubs pour les dépendances externes

Après les tests, fournis :

  • Taux de couverture estimé
  • Cas non couverts identifiés et pourquoi
  • Suggestion pour les tests d'intégration complémentaires

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

The enforced naming convention produces readable, self-documenting tests. The separation into 5 case categories replicates an experienced tester mental checklist. Requesting coverage rate and identified gaps makes the result immediately actionable.

Use Cases

Adding tests to legacy codePracticing TDD on a new featurePreparing a code review with test coverage

Expected Output

A complete test suite with nominal, edge and error cases, coverage estimate, uncovered cases and integration test suggestions.

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é, couple ce prompt à un générateur de données réalistes (ex: Faker, factory_boy) pour automatiser les cas limites et les données aléatoires. Ajoute aussi une variante pour les tests paramétrés ou de tableaux, ce qui rendra la suite plus compacte sans sacrifier la couverture.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further