참고 항목
- Copilot prompt files are in 공개 미리 보기 and subject to change. Prompt files are only available in VS Code. See GitHub Copilot Chat 응답 사용자 지정 정보.
- For community-contributed examples of prompt files for specific languages and scenarios, see the Awesome GitHub Copilot Customizations repository.
이 프롬프트 파일은 실제 테스트 사례와 유지 관리 가능한 코드를 강조하여 특정 함수나 메서드에 대한 집중적인 단위 테스트를 만듭니다.
단위 테스트 생성 프롬프트
--- 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.
이 프롬프트 파일을 사용하는 방법
- 위 콘텐츠를
.github/prompts
폴더에generate-unit-tests.prompt.md
로 저장합니다. - 테스트할 함수가 포함된 코드 파일을 엽니다. 필요에 따라, 특정 함수를 강조 표시할 수 있습니다.
- Visual Studio Code에서 Copilot Chat 보기를 표시하고
/generate-unit-tests
를 입력합니다. 필요에 따라,function_name=fetchActivities
및framework=pytest
와 같이 입력하여 대상 함수와 테스트 프레임워크를 지정할 수도 있습니다.
Further reading
- Use prompt files in Visual Studio Code in the Visual Studio Code documentation - Information on how to create and use prompt files
- GitHub Copilot Chat 응답 사용자 지정 정보 - Overview of response customization in GitHub Copilot
- Awesome GitHub Copilot Customizations - Repository of community-contributed custom prompt files and other customizations for specific languages and scenarios