{"meta":{"title":"Testing automation","intro":"File-specific instructions for writing unit tests.","product":"GitHub Copilot","breadcrumbs":[{"href":"/en/copilot","title":"GitHub Copilot"},{"href":"/en/copilot/tutorials","title":"Tutorials"},{"href":"/en/copilot/tutorials/customization-library","title":"Customization library"},{"href":"/en/copilot/tutorials/customization-library/custom-instructions","title":"Custom instructions"},{"href":"/en/copilot/tutorials/customization-library/custom-instructions/testing-automation","title":"Testing automation"}],"documentType":"article"},"body":"# Testing automation\n\nFile-specific instructions for writing unit tests.\n\n> \\[!NOTE]\n>\n> * The examples in this library are intended for inspiration—you are encouraged to adjust them to be more specific to your projects, languages, and team processes.\n> * For community-contributed examples of custom instructions for specific languages and scenarios, see the [Awesome GitHub Copilot Customizations](https://github.com/github/awesome-copilot/blob/main/docs/README.instructions.md) repository.\n> * You can apply custom instructions across different scopes, depending on the platform or IDE where you are creating them. For more information, see \"[About customizing GitHub Copilot responses](/en/copilot/concepts/response-customization).\"\n\nThis example shows a path-specifc `python-tests.instructions.md` file that applies only to Python test files in your repository, using the `applyTo` field. For more information about path-specific instructions files, see [Adding repository custom instructions for GitHub Copilot](/en/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````"}