사용자 상호작용을 테스트하면 사용자가 앱과 상호작용할 때 예기치 않은 결과가 발생하거나 불만족스러운 경험을 하지 않도록 할 수 있습니다. 앱의 UI가 올바르게 작동하는지 확인해야 하는 경우 사용자 인터페이스 (UI) 테스트를 만드는 습관을 들여야 합니다.
UI 테스트에 대한 한 가지 접근 방식은 테스터가 타겟 앱에서 일련의 사용자 작업을 실행하도록 하고 올바르게 작동하는지 확인하는 것입니다. 하지만 이 수동 접근 방식은 시간이 오래 걸리고 오류가 발생하기 쉽습니다. 보다 효율적인 접근 방식은 사용자 작업이 자동화된 방식으로 실행되도록 UI 테스트를 작성하는 것입니다. 자동화된 접근 방식을 사용하면 반복 가능한 방식으로 테스트를 빠르고 안정적으로 실행할 수 있습니다.
UI 테스트는 앱 (또는 일부)을 실행한 다음 사용자 상호작용을 시뮬레이션하고 마지막으로 앱이 적절하게 반응했는지 확인합니다. 이는 소규모 구성요소의 동작 확인부터 전체 사용자 흐름을 통과하는 대규모 탐색 테스트에 이르기까지 다양한 통합 테스트입니다. 회귀를 확인하고 다양한 API 수준 및 실제 기기와의 호환성을 확인하는 데 유용합니다.
UI 테스트 실행
Android 스튜디오를 사용하여 계측 UI 테스트를 실행하려면 별도의 Android 테스트 폴더인 src/androidTest/java에 테스트 코드를 구현합니다. Android Gradle 플러그인은 테스트 코드를 기반으로 테스트 앱을 빌드한 다음 타겟 앱과 동일한 기기에 테스트 앱을 로드합니다. 테스트 코드에서 UI 테스트 프레임워크를 사용하여 특정 사용 시나리오를 포괄하는 테스트 작업을 실행하기 위해 타겟 앱에서 사용자 상호작용을 시뮬레이션할 수 있습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Automate UI tests\n\nTesting user interactions helps ensure users don't encounter unexpected results\nor have a poor experience when interacting with your app. You should get into\nthe habit of creating user interface (UI) tests if you need to verify that the\nUI of your app is functioning correctly.\n\nOne approach to UI testing is to have a human tester perform a set of user\noperations on the target app and verify that it is behaving correctly. However,\nthis manual approach can be time-consuming and error-prone. A more efficient\napproach is to write your UI tests such that user actions are performed in an\nautomated way. The automated approach lets you run your tests quickly and\nreliably in a repeatable manner.\n\nUI tests launch an app (or part of it), then simulate user interactions, and\nfinally check that the app reacted appropriately. They are integration tests\nthat can range from verifying the behavior of a small component to a large\nnavigation test that traverses a whole user flow. They are useful to check for\nregressions and to verify compatibility with different API levels and physical\ndevices.\n\nRun UI tests\n------------\n\n- To run [instrumented](/training/testing/instrumented-tests) UI tests using Android Studio, you implement your test code in a separate Android test folder - `src/androidTest/java`. The [Android Gradle Plugin](/studio/releases/gradle-plugin) builds a test app based on your test code, then loads the test app on the same device as the target app. In your test code, you can use UI testing frameworks to simulate user interactions on the target app, in order to perform testing tasks that cover specific usage scenarios.\n- You can also use [Robolectric](/training/testing/local-tests/robolectric#ui-testing) to run UI tests on the JVM.\n\nArchitecture and test setup\n---------------------------\n\nThe architecture of your app should let tests replace parts of it for [testing\ndoubles](/training/testing/fundamentals/test-doubles) and you should use libraries that provide utilities to help with\ntesting. For example, you can replace a data repository module with an in-memory\nversion of it that provides fake, deterministic data to the test.\n\n\u003cbr /\u003e\n\n**Figure 3**: Testing a UI by replacing its dependencies with fakes.\n\n\u003cbr /\u003e\n\nThe recommended approach to replace dependencies is dependency injection. You\ncan create your own system [manually](/training/dependency-injection/manual) but we recommend using a DI framework\nlike [Hilt](/training/dependency-injection/hilt-android) for this.\n\nWhy test UIs automatically?\n---------------------------\n\nAn Android app can target thousands of different devices across many API levels\nand form factors, and the high level of customization that the OS brings to the\nuser means your app could be rendered incorrectly or even crash on some devices.\n\nUI testing lets you do *compatibility testing*, verifying the behavior of an app\nin different contexts. You might want to run your UI tests on devices that vary\nin the following ways:\n\n- **API level**: 21, 25, and 30.\n- **Locale**: English, Arabic, and Chinese.\n- **Orientation**: Portrait, landscape.\n\nMoreover, apps should check the behavior beyond phones. You should test on\ntablets, foldables, and other devices. Read more about [testing different screen\nsizes](/training/testing/different-screens).\n\nTypes of UI Tests\n-----------------\n\nThis section covers two types of UI tests:\n\n- [Behavior tests](/training/testing/ui-tests/behavior) analyze the UI hierarchy to make assertions on the properties of the UI elements.\n- [Screenshot tests](/training/testing/ui-tests/screenshot) take screenshots of a UI and compares them with a previously-approved images."]]