{"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/custom-instructions","title":"カスタム指示"},{"href":"/ja/copilot/tutorials/customization-library/custom-instructions/testing-automation","title":"テストの自動化"}],"documentType":"article"},"body":"# テストの自動化\n\n単体テストを記述するためのファイル固有の手順。\n\n> \\[!NOTE]\n>\n> * このライブラリの例はインスピレーションを得るためのものです。プロジェクト、言語、チーム プロセスに合わせて具体的に調整することをお勧めします。\n> * 特定の言語とシナリオ向けのカスタム指示のコミュニティに投稿された例については、[Awesome GitHub Copilot Customizations](https://github.com/github/awesome-copilot/blob/main/docs/README.instructions.md) リポジトリを参照してください。\n> * カスタム指示は、作成するプラットフォームまたは IDE に応じて、さまざまなスコープにわたって適用できます。 詳しくは、「[GitHub Copilotの応答をカスタマイズする方法](/ja/copilot/concepts/response-customization)」を参照してください。\n\nこの例では、`python-tests.instructions.md` フィールドを使用してリポジトリ内の Python テスト ファイルにのみ適用される、パス固有の `applyTo` ファイルを示します。 パス固有の手順ファイルの詳細については、「[GitHub Copilot用のリポジトリカスタム命令の追加](/ja/copilot/how-tos/configure-custom-instructions/add-repository-instructions#using-one-or-more-instructionsmd-files)」を参照してください。\n\n````text copy\n---\napplyTo: \"tests/**/*.py\"\n---\n\nWhen writing Python tests:\n\n## Test Structure Essentials\n- Use pytest as the primary testing framework\n- Follow AAA pattern: Arrange, Act, Assert\n- Write descriptive test names that explain the behavior being tested\n- Keep tests focused on one specific behavior\n\n## Key Testing Practices\n- Use pytest fixtures for setup and teardown\n- Mock external dependencies (databases, APIs, file operations)\n- Use parameterized tests for testing multiple similar scenarios\n- Test edge cases and error conditions, not just happy paths\n\n## Example Test Pattern\n```python\nimport pytest\nfrom unittest.mock import Mock, patch\n\nclass TestUserService:\n    @pytest.fixture\n    def user_service(self):\n        return UserService()\n\n    @pytest.mark.parametrize(\"invalid_email\", [\"\", \"invalid\", \"@test.com\"])\n    def test_should_reject_invalid_emails(self, user_service, invalid_email):\n        with pytest.raises(ValueError, match=\"Invalid email\"):\n            user_service.create_user({\"email\": invalid_email})\n\n    @patch('src.user_service.email_validator')\n    def test_should_handle_validation_failure(self, mock_validator, user_service):\n        mock_validator.validate.side_effect = ConnectionError()\n\n        with pytest.raises(ConnectionError):\n            user_service.create_user({\"email\": \"test@example.com\"})\n```\n````"}