Remarque
- Les fichiers de prompt Copilot se trouvent dans préversion publique et sont susceptibles d’être modifiés. Les fichiers d’invite sont disponibles uniquement dans VS Code, Visual Studio, et les IDE JetBrains. Voir À propos de la personnalisation des réponses GitHub Copilot.
- Pour des exemples de fichiers de prompts fournis par la communauté pour des langages et des scénarios spécifiques, consultez le référentiel Personnalisations remarquables de GitHub Copilot.
Ce fichier de prompt génère des tests unitaires ciblés pour des fonctions ou méthodes spécifiques, en mettant l’accent sur des cas de test pratiques et un code facile à gérer.
Prompt pour génération de tests unitaires
---
agent: 'agent'
description: 'Generate unit tests for selected functions or methods'
---
## Task
Analyze the selected function/method and generate focused unit tests that thoroughly validate its behavior.
## Test Generation Strategy
1. **Core Functionality Tests**
- Test the main purpose/expected behavior
- Verify return values with typical inputs
- Test with realistic data scenarios
2. **Input Validation Tests**
- Test with invalid input types
- Test with null/undefined values
- Test with empty strings/arrays/objects
- Test boundary values (min/max, zero, negative numbers)
3. **Error Handling Tests**
- Test expected exceptions are thrown
- Verify error messages are meaningful
- Test graceful handling of edge cases
4. **Side Effects Tests** (if applicable)
- Verify external calls are made correctly
- Test state changes
- Validate interactions with dependencies
## Test Structure Requirements
- Use existing project testing framework and patterns
- Follow AAA pattern: Arrange, Act, Assert
- Write descriptive test names that explain the scenario
- Group related tests in describe/context blocks
- Mock external dependencies cleanly
Target function: ${input:function_name:Which function or method should be tested?}
Testing framework: ${input:framework:Which framework? (jest/vitest/mocha/pytest/rspec/etc)}
## Guidelines
- Generate 5-8 focused test cases covering the most important scenarios
- Include realistic test data, not just simple examples
- Add comments for complex test setup or assertions
- Ensure tests are independent and can run in any order
- Focus on testing behavior, not implementation details
Create tests that give confidence the function works correctly and help catch regressions.
---
agent: 'agent'
description: 'Generate unit tests for selected functions or methods'
---
## Task
Analyze the selected function/method and generate focused unit tests that thoroughly validate its behavior.
## Test Generation Strategy
1. **Core Functionality Tests**
- Test the main purpose/expected behavior
- Verify return values with typical inputs
- Test with realistic data scenarios
2. **Input Validation Tests**
- Test with invalid input types
- Test with null/undefined values
- Test with empty strings/arrays/objects
- Test boundary values (min/max, zero, negative numbers)
3. **Error Handling Tests**
- Test expected exceptions are thrown
- Verify error messages are meaningful
- Test graceful handling of edge cases
4. **Side Effects Tests** (if applicable)
- Verify external calls are made correctly
- Test state changes
- Validate interactions with dependencies
## Test Structure Requirements
- Use existing project testing framework and patterns
- Follow AAA pattern: Arrange, Act, Assert
- Write descriptive test names that explain the scenario
- Group related tests in describe/context blocks
- Mock external dependencies cleanly
Target function: ${input:function_name:Which function or method should be tested?}
Testing framework: ${input:framework:Which framework? (jest/vitest/mocha/pytest/rspec/etc)}
## Guidelines
- Generate 5-8 focused test cases covering the most important scenarios
- Include realistic test data, not just simple examples
- Add comments for complex test setup or assertions
- Ensure tests are independent and can run in any order
- Focus on testing behavior, not implementation details
Create tests that give confidence the function works correctly and help catch regressions.
Comment utiliser ce fichier d’invite
- Enregistrez le contenu ci-dessus en tant que
generate-unit-tests.prompt.mddans votre dossier.github/prompts. - Ouvrez le fichier de code contenant la ou les fonctions que vous souhaitez tester. Vous pouvez éventuellement mettre en évidence une fonction spécifique.
- Dans Visual Studio Code, affichez la vue Copilot Chat et saisissez
/generate-unit-tests. Vous pouvez également spécifier la fonction cible et l’infrastructure de test en tapantfunction_name=fetchActivitiesetframework=pytest, par exemple.
Pour aller plus loin
-
[Utilisez les fichiers de prompt dans Visual Studio Code](https://code.visualstudio.com/docs/copilot/customization/prompt-files) dans la documentation Visual Studio Code - Informations sur la création et l’utilisation des fichiers de prompt -
[AUTOTITLE](/copilot/concepts/response-customization) - Vue d’ensemble de la personnalisation des réponses dans GitHub Copilot -
[Personnalisations remarquables de GitHub Copilot](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md) - Référentiel de fichiers de prompts personnalisés fournis par la communauté et d’autres personnalisations pour des langages et des scénarios spécifiques