하이브리드 앱에서는 뷰 계층 구조 내부의 Compose 구성요소와 Compose 컴포저블 내부의 뷰를 찾을 수 있습니다 (AndroidView 컴포저블을 통해).
두 유형을 일치시키기 위해 특별한 단계가 필요하지는 않습니다. Espresso의 onView로 뷰를 일치시키고 ComposeTestRule로 Compose 요소를 일치시킵니다.
@TestfunandroidViewInteropTest(){// Check the initial state of a TextView that depends on a Compose state.Espresso.onView(withText("Hello Views")).check(matches(isDisplayed()))// Click on the Compose button that changes the state.composeTestRule.onNodeWithText("Click here").performClick()// Check the new value.Espresso.onView(withText("Hello Compose")).check(matches(isDisplayed()))}
UiAutomator와의 상호 운용성
기본적으로 컴포저블은 편리한 설명자 (표시된 텍스트, 콘텐츠 설명 등)를 통해서만 UiAutomator에 액세스할 수 있습니다. Modifier.testTag를 사용하는 모든 컴포저블에 액세스하려면 특정 컴포저블의 하위 트리에 testTagsAsResourceId 시맨틱 속성을 사용 설정해야 합니다. 이 동작을 사용 설정하면 스크롤 가능한 컴포저블과 같이 다른 고유 핸들이 없는 컴포저블 (예: LazyColumn)에 유용합니다.
UiAutomator에서 Modifier.testTag와 함께 중첩된 모든 컴포저블에 액세스할 수 있도록 컴포저블 계층 구조에서 한 번만 시맨틱 속성을 사용 설정하세요.
Scaffold(// Enables for all composables in the hierarchy.modifier=Modifier.semantics{testTagsAsResourceId=true}){// Modifier.testTag is accessible from UiAutomator for composables nested here.LazyColumn(modifier=Modifier.testTag("myLazyColumn")){// Content}}
Modifier.testTag(tag)를 포함하는 모든 컴포저블은 resourceName과 동일한 tag로 By.res(resourceName)을 사용하여 액세스할 수 있습니다.
valdevice=UiDevice.getInstance(getInstrumentation())vallazyColumn:UiObject2=device.findObject(By.res("myLazyColumn"))// Some interaction with the lazyColumn.
추가 리소스
Android에서 앱 테스트: Android 테스트 기본사항 및 기법에 관한 광범위한 정보를 제공하는 기본 Android 테스트 방문 페이지입니다.
다양한 화면 크기 테스트: 사용자가 사용할 수 있는 기기가 많으므로 다양한 화면 크기를 테스트해야 합니다.
Espresso: Espresso는 뷰 기반 UI를 위한 것이지만 Compose 테스트의 일부 측면에서는 여전히 유용할 수 있습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-08-21(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-08-21(UTC)"],[],[],null,["# Interoperability\n\nCompose integrates with common testing frameworks.\n\nInteroperability with Espresso\n------------------------------\n\nIn a hybrid app, you can find Compose components inside view hierarchies and\nviews inside Compose composables (via the [`AndroidView`](/reference/kotlin/androidx/compose/ui/viewinterop/package-summary#AndroidView(kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Function1)) composable).\n\nThere are no special steps needed to match either type. You match views with\nEspresso's [`onView`](/reference/androidx/test/espresso/Espresso#onView(org.hamcrest.Matcher%3Candroid.view.View%3E)), and Compose elements with the [`ComposeTestRule`](/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule). \n\n @Test\n fun androidViewInteropTest() {\n // Check the initial state of a TextView that depends on a Compose state.\n Espresso.onView(withText(\"Hello Views\")).check(matches(isDisplayed()))\n // Click on the Compose button that changes the state.\n composeTestRule.onNodeWithText(\"Click here\").performClick()\n // Check the new value.\n Espresso.onView(withText(\"Hello Compose\")).check(matches(isDisplayed()))\n }\n\nInteroperability with UiAutomator\n---------------------------------\n\nBy default, composables are accessible from [UiAutomator](/training/testing/other-components/ui-automator) only by their\nconvenient descriptors (displayed text, content description, etc.). If you want\nto access any composable that uses [`Modifier.testTag`](/reference/kotlin/androidx/compose/ui/Modifier#(androidx.compose.ui.Modifier).testTag(kotlin.String)), you need to enable\nthe semantic property `testTagsAsResourceId` for the particular composable's\nsubtree. Enabling this behavior is useful for composables that don't have any\nother unique handle, such as scrollable composables (for example, `LazyColumn`).\n| **Note:** This feature is available in Jetpack Compose version 1.2.0-alpha08 and higher.\n\nEnable the semantic property only once high in your composables hierarchy to\nensure all nested composables with `Modifier.testTag` are accessible from\nUiAutomator. \n\n Scaffold(\n // Enables for all composables in the hierarchy.\n modifier = Modifier.semantics {\n testTagsAsResourceId = true\n }\n ){\n // Modifier.testTag is accessible from UiAutomator for composables nested here.\n LazyColumn(\n modifier = Modifier.testTag(\"myLazyColumn\")\n ){\n // Content\n }\n }\n\nAny composable with the `Modifier.testTag(tag)` can be accessible with the use\nof [`By.res(resourceName)`](/reference/androidx/test/uiautomator/BySelector#res) using the same `tag` as the `resourceName`.\n**Caution:** Make sure you don't use [`By.res(resourcePackage, resourceId)`](/reference/androidx/test/uiautomator/BySelector#res_1) as this formats the argument as `$resourcePackage:id/$resourceId`, which is different from `Modifier.testTag`. \n\n val device = UiDevice.getInstance(getInstrumentation())\n\n val lazyColumn: UiObject2 = device.findObject(By.res(\"myLazyColumn\"))\n // Some interaction with the lazyColumn.\n\nAdditional Resources\n--------------------\n\n- **[Test apps on Android](/training/testing)**: The main Android testing landing page provides a broader view of testing fundamentals and techniques.\n- **[Fundamentals of testing](/training/testing/fundamentals):** Learn more about the core concepts behind testing an Android app.\n- **[Local tests](/training/testing/local-tests):** You can run some tests locally, on your own workstation.\n- **[Instrumented tests](/training/testing/instrumented-tests):** It is good practice to also run instrumented tests. That is, tests that run directly on-device.\n- **[Continuous integration](/training/testing/continuous-integration):** Continuous integration lets you integrate your tests into your deployment pipeline.\n- **[Test different screen sizes](/training/testing/different-screens):** With some many devices available to users, you should test for different screen sizes.\n- **[Espresso](/training/testing/espresso)**: While intended for View-based UIs, Espresso knowledge can still be helpful for some aspects of Compose testing."]]