Hinweis
- Copilot-Promptdateien befinden sich in der öffentliche Vorschau. Änderungen sind vorbehalten. Promptdateien sind nur in VS Code, Visual Studio und JetBrains-IDEs verfügbar. Siehe Informationen zum Anpassen der GitHub Copilot-Antworten.
- Beispiele für von der Community bereitgestellte Promptdateien für bestimmte Sprachen und Szenarios findest du im Repository Großartige GitHub Copilot-Anpassungen.
Diese Promptdatei generiert fokussierte Komponententests für bestimmte Funktionen oder Methoden und hebt praktische Testfälle und verwaltbaren Code hervor.
Prompt zur Generierung von Komponententests
---
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.
Anleitung zur Verwendung dieser Promptdatei
- Speichern Sie den obigen Inhalt als
generate-unit-tests.prompt.mdim Ordner.github/prompts. - Öffne die Codedatei mit den Funktionen, für die du Tests durchführen möchtest. Optional kannst du eine bestimmte Funktion hervorheben.
- Zeige in Visual Studio Code die Copilot-Chat-Ansicht an, und gib
/generate-unit-testsein. Optional kannst du außerdem die Zielfunktion und das Testframework angeben, indem du z. B.function_name=fetchActivitiesundframework=pytesteingibst.
Weitere Informationen
-
[Verwenden von Promptdateien in Visual Studio Code](https://code.visualstudio.com/docs/copilot/customization/prompt-files) in der Visual Studio Code-Dokumentation: Informationen zum Erstellen und Verwenden von Promptdateien -
[AUTOTITLE](/copilot/concepts/response-customization): Übersicht über die Anpassung von Antworten in GitHub Copilot -
[Großartige GitHub Copilot-Anpassungen](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md): Repository der durch die Community bereitgestellten benutzerdefinierten Promptdateien und weiterer Anpassungen für bestimmte Sprachen und Szenarios