P
IntermediateAll AIs

Write comprehensive unit tests for a function

Generate a complete suite of unit tests following the AAA pattern, covering all nominal, edge case, 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 imposed naming convention produces tests that are readable and self-documented. The separation into 5 case categories reproduces the mental checklist of an experienced tester. The request for coverage rate and identified gaps makes the result immediately actionable.

Use Cases

Add tests to legacy codePractice TDD on a new featurePrepare a code review with test coverage

Expected Output

Complete test suite with nominal, boundary and error cases, coverage estimation, uncovered cases and integration testing suggestions.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide