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
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.
Learn more
Check the full skill on Prompt Guide to master this technique from A to Z.
View on Prompt Guide📬 Get new prompts every week
Join our newsletter and never miss a prompt.