Observação
- Os arquivos de prompt do Copilot estão no versão prévia pública e sujeitos a alterações. Arquivos de prompt estão disponíveis somente no VS Code. Confira Sobre como personalizar as respostas do GitHub Copilot Chat.
- Para obter exemplos de arquivos de prompt com contribuição da comunidade para linguagens e cenários específicos, confira o repositório Personalizações incríveis do GitHub Copilot.
Esse arquivo de prompt gera testes de unidade focados para funções ou métodos específicos, enfatizando casos de teste práticos e código que pode receber manutenção.
Prompt de geração de teste de unidade
--- mode: '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.
---
mode: '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.
Como usar este arquivo de prompt
- Salve o conteúdo acima como
generate-unit-tests.prompt.md
em sua pasta.github/prompts
. - Abra o arquivo de código que contém as funções para as quais você deseja criar testes. Opcionalmente, você pode realçar uma função específica.
- No Visual Studio Code, abra a exibição do Copilot Chat e insira
/generate-unit-tests
. Outra alternativa é especificar a função de destino e a estrutura de teste digitandofunction_name=fetchActivities
eframework=pytest
, por exemplo.
Leitura adicional
- Usar arquivos de prompt no Visual Studio Code na documentação do Visual Studio Code – Informações sobre como criar e usar arquivos de prompt
- Sobre como personalizar as respostas do GitHub Copilot Chat – Visão geral da personalização de resposta no GitHub Copilot
- Personalizações incríveis do GitHub Copilot – repositório de arquivos de prompt personalizados com a contribuição da comunidade e outras personalizações para linguagens e cenários específicos