{"meta":{"title":"単体テストを生成する","intro":"コードのための焦点を当てた単体テストを作成します。","product":"GitHub Copilot","breadcrumbs":[{"href":"/ja/copilot","title":"GitHub Copilot"},{"href":"/ja/copilot/tutorials","title":"チュートリアル"},{"href":"/ja/copilot/tutorials/customization-library","title":"カスタマイズ ライブラリ"},{"href":"/ja/copilot/tutorials/customization-library/prompt-files","title":"プロンプトファイル"},{"href":"/ja/copilot/tutorials/customization-library/prompt-files/generate-unit-tests","title":"単体テストを生成する"}],"documentType":"article"},"body":"# 単体テストを生成する\n\nコードのための焦点を当てた単体テストを作成します。\n\n> \\[!NOTE]\n>\n> * Copilot プロンプト ファイルは パブリック プレビュー 段階であり、変更される可能性があります。 プロンプト ファイルは、VS Code、Visual Studio、および JetBrains IDE でのみ使用できます。「[GitHub Copilotの応答をカスタマイズする方法](/ja/copilot/concepts/prompting/response-customization#about-prompt-files)」を参照してください。\n> * 特定の言語とシナリオ向けの、コミュニティに投稿されたプロンプト ファイルの例については、[Awesome GitHub Copilot Customizations](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md) リポジトリを参照してください。\n\nこのプロンプト ファイルは、実用的なテスト ケースと保守が容易なコードに重点を置いて、特定の関数またはメソッドに焦点を当てた単体テストを生成します。\n\n## 単体テスト生成プロンプト\n\n```text copy\n---\nagent: 'agent'\ndescription: 'Generate unit tests for selected functions or methods'\n---\n\n## Task\n\nAnalyze the selected function/method and generate focused unit tests that thoroughly validate its behavior.\n\n## Test Generation Strategy\n\n1. **Core Functionality Tests**\n   - Test the main purpose/expected behavior\n   - Verify return values with typical inputs\n   - Test with realistic data scenarios\n\n2. **Input Validation Tests**\n   - Test with invalid input types\n   - Test with null/undefined values\n   - Test with empty strings/arrays/objects\n   - Test boundary values (min/max, zero, negative numbers)\n\n3. **Error Handling Tests**\n   - Test expected exceptions are thrown\n   - Verify error messages are meaningful\n   - Test graceful handling of edge cases\n\n4. **Side Effects Tests** (if applicable)\n   - Verify external calls are made correctly\n   - Test state changes\n   - Validate interactions with dependencies\n\n## Test Structure Requirements\n\n- Use existing project testing framework and patterns\n- Follow AAA pattern: Arrange, Act, Assert\n- Write descriptive test names that explain the scenario\n- Group related tests in describe/context blocks\n- Mock external dependencies cleanly\n\nTarget function: ${input:function_name:Which function or method should be tested?}\nTesting framework: ${input:framework:Which framework? (jest/vitest/mocha/pytest/rspec/etc)}\n\n## Guidelines\n\n- Generate 5-8 focused test cases covering the most important scenarios\n- Include realistic test data, not just simple examples\n- Add comments for complex test setup or assertions\n- Ensure tests are independent and can run in any order\n- Focus on testing behavior, not implementation details\n\nCreate tests that give confidence the function works correctly and help catch regressions.\n```\n\n## このプロンプト ファイルの使用方法\n\n1. 上記の内容を `generate-unit-tests.prompt.md` として `.github/prompts` フォルダーに保存します。\n2. テスト対象の関数を含むコード ファイルを開きます。 必要に応じて、特定の関数を強調表示できます。\n3. Visual Studio Code で コパイロットチャット ビューに、「`/generate-unit-tests`」と入力します。 必要に応じて、`function_name=fetchActivities` と `framework=pytest` などを入力して、対象となる関数とテスト フレームワークを指定することもできます。\n\n## 参考資料\n\n* Visual Studio Code ドキュメントの「[Visual Studio Code でプロンプト ファイルを使う](https://code.visualstudio.com/docs/copilot/customization/prompt-files)」- プロンプト ファイルの作成と使用の方法に関する情報\n* [GitHub Copilotの応答をカスタマイズする方法](/ja/copilot/concepts/response-customization) - GitHub Copilot での応答カスタマイズの概要\n* [優れた GitHub Copilot カスタマイズ](https://github.com/github/awesome-copilot/blob/main/docs/README.prompts.md) - コミュニティに投稿されたカスタム プロンプト ファイルや、特定の言語やシナリオ向けのその他のカスタマイズのリポジトリ"}