{"meta":{"title":"Автоматизация тестирования","intro":"Инструкции по написанию модульных тестов для конкретного файла.","product":"GitHub Copilot","breadcrumbs":[{"href":"/ru/copilot","title":"GitHub Copilot"},{"href":"/ru/copilot/tutorials","title":"Учебники"},{"href":"/ru/copilot/tutorials/customization-library","title":"Библиотека настройки"},{"href":"/ru/copilot/tutorials/customization-library/custom-instructions","title":"Пользовательские инструкции"},{"href":"/ru/copilot/tutorials/customization-library/custom-instructions/testing-automation","title":"Автоматизация тестирования"}],"documentType":"article"},"body":"# Автоматизация тестирования\n\nИнструкции по написанию модульных тестов для конкретного файла.\n\n> \\[!NOTE]\n>\n> * Примеры, приведенные в этой библиотеке, предназначены для вдохновения— рекомендуется настроить их для более конкретных проектов, языков и командных процессов.\n> * Примеры пользовательских инструкций для определенных языков и сценариев в сообществе см. в [репозитории GitHub Copilot Customs](https://github.com/github/awesome-copilot/blob/main/docs/README.instructions.md) .\n> * Пользовательские инструкции можно применять в разных областях в зависимости от платформы или интегрированной среды разработки, в которой вы создаете их. Дополнительные сведения см. в разделе «[О кастомизации ответов GitHub Copilot](/ru/copilot/concepts/response-customization)».\n\nВ этом примере показан файл path-specifc `python-tests.instructions.md` , который применяется только к тестовых файлам Python в репозитории `applyTo` с помощью поля. Дополнительные сведения о файлах инструкций, относящихся к пути, см. в разделе [Добавление пользовательских инструкций репозитория для GitHub Copilot](/ru/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````"}