संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Compose, टेस्टिंग के सामान्य फ़्रेमवर्क के साथ इंटिग्रेट होता है.
Espresso के साथ इंटरऑपरेबिलिटी की सुविधा
हाइब्रिड ऐप्लिकेशन में, आपको व्यू हैरारकी के अंदर 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).
सिमेंटिक प्रॉपर्टी को कंपोज़ेबल के हाइरार्की में सिर्फ़ एक बार चालू करें, ताकि Modifier.testTag वाले सभी नेस्टेड कंपोज़ेबल को UiAutomator से ऐक्सेस किया जा सके.
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) के साथ कंपोज़ किए जा सकने वाले किसी भी आइटम को By.res(resourceName) का इस्तेमाल करके ऐक्सेस किया जा सकता है. इसके लिए, resourceName के तौर पर इस्तेमाल किए गए tag का ही इस्तेमाल किया जाता है.
valdevice=UiDevice.getInstance(getInstrumentation())vallazyColumn:UiObject2=device.findObject(By.res("myLazyColumn"))// Some interaction with the lazyColumn.
अतिरिक्त संसाधन
Android पर ऐप्लिकेशन की टेस्टिंग करना: Android टेस्टिंग के मुख्य लैंडिंग पेज पर, टेस्टिंग की बुनियादी बातों और तकनीकों के बारे में ज़्यादा जानकारी मिलती है.
टेस्टिंग की बुनियादी बातें: Android ऐप्लिकेशन की टेस्टिंग से जुड़े मुख्य कॉन्सेप्ट के बारे में ज़्यादा जानें.
लोकल टेस्ट: कुछ टेस्ट, अपने वर्कस्टेशन पर स्थानीय तौर पर चलाए जा सकते हैं.
इंस्ट्रुमेंटेड टेस्ट: इंस्ट्रुमेंटेड टेस्ट भी चलाए जाने चाहिए. इसका मतलब है कि ऐसे टेस्ट जो सीधे तौर पर डिवाइस पर चलते हैं.
लगातार इंटिग्रेशन करना:
लगातार इंटिग्रेशन करने की सुविधा की मदद से, अपनी जांचों को डिप्लॉयमेंट पाइपलाइन में इंटिग्रेट किया जा सकता है.
Espresso: इसे व्यू पर आधारित यूज़र इंटरफ़ेस (यूआई) के लिए बनाया गया है. हालांकि, Espresso की जानकारी, Compose की टेस्टिंग के कुछ पहलुओं के लिए अब भी मददगार हो सकती है.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, 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."]]