আপনার রচনা লেআউট পরীক্ষা করুন
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আপনার রচনা কোডের আচরণ সঠিক কিনা তা যাচাই করতে আপনার অ্যাপের UI পরীক্ষা করুন। এটি আপনাকে তাড়াতাড়ি ত্রুটিগুলি ধরতে এবং আপনার অ্যাপের গুণমান উন্নত করতে দেয়৷
রচনা উপাদানগুলি সন্ধান করতে, তাদের বৈশিষ্ট্যগুলি যাচাই করতে এবং ব্যবহারকারীর ক্রিয়া সম্পাদন করতে পরীক্ষার API এর একটি সেট সরবরাহ করে। এপিআই-এ টাইম ম্যানিপুলেশনের মতো উন্নত বৈশিষ্ট্যও রয়েছে। আপনার অ্যাপের আচরণ যাচাই করে এমন শক্তিশালী পরীক্ষা তৈরি করতে এই APIগুলি ব্যবহার করুন।
ভিউ
আপনি যদি রচনার পরিবর্তে ভিউ নিয়ে কাজ করেন তবে অ্যান্ড্রয়েড বিভাগে সাধারণ পরীক্ষা অ্যাপগুলি দেখুন।
বিশেষ করে, শুরু করার জন্য একটি ভাল জায়গা হল স্বয়ংক্রিয় UI পরীক্ষার নির্দেশিকা। এটি বর্ণনা করে যে আপনি কীভাবে ভিউ ব্যবহার করার সময় সহ ডিভাইসে চালানো পরীক্ষাগুলিকে স্বয়ংক্রিয় করতে পারেন।
মূল ধারণা
আপনার রচনা কোড পরীক্ষা করার জন্য নিম্নলিখিত কিছু মূল ধারণা রয়েছে:
- শব্দার্থবিদ্যা : শব্দার্থবিদ্যা আপনার UI কে অর্থ দেয়, পরীক্ষাগুলিকে নির্দিষ্ট উপাদানগুলির সাথে ইন্টারঅ্যাক্ট করার অনুমতি দেয়।
- টেস্টিং এপিআই : টেস্টিং এপিআই আপনাকে উপাদানগুলি খুঁজে পেতে, তাদের বৈশিষ্ট্যগুলি যাচাই করতে এবং ব্যবহারকারীর ক্রিয়া সম্পাদন করতে দেয়।
- সিঙ্ক্রোনাইজেশন : সিঙ্ক্রোনাইজেশন যাচাই করে যে পরীক্ষাগুলি ক্রিয়া সম্পাদন বা দাবী করার আগে UI নিষ্ক্রিয় হওয়ার জন্য অপেক্ষা করে।
- ইন্টারঅপারেবিলিটি : ইন্টারঅপারেবিলিটি একই অ্যাপে কম্পোজ এবং ভিউ-ভিত্তিক উভয় উপাদানের সাথে কাজ করতে পরীক্ষাকে সক্ষম করে।
টেস্টিং চিটশিট
কম্পোজে পরীক্ষা করার বিষয়ে আপনার যে সমস্ত মূল বিষয়গুলি শিখতে হবে তার একটি ওভারভিউয়ের জন্য টেস্টিং চিটশিটটি দেখুন।
সেটআপ
কম্পোজ কোড পরীক্ষা করার জন্য আপনার অ্যাপ সেট আপ করুন।
প্রথমে, আপনার UI পরীক্ষা ধারণকারী মডিউলের build.gradle
ফাইলে নিম্নলিখিত নির্ভরতা যোগ করুন:
// Test rules and transitive dependencies:
androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version")
// Needed for createComposeRule(), but not for createAndroidComposeRule<YourActivity>():
debugImplementation("androidx.compose.ui:ui-test-manifest:$compose_version")
এই মডিউলটিতে AndroidComposeTestRule
নামে একটি ComposeTestRule
এবং অ্যান্ড্রয়েডের জন্য একটি বাস্তবায়ন অন্তর্ভুক্ত রয়েছে। এই নিয়মের মাধ্যমে আপনি রচনা সামগ্রী সেট করতে পারেন বা কার্যকলাপ অ্যাক্সেস করতে পারেন। আপনি ফ্যাক্টরি ফাংশন ব্যবহার করে নিয়ম তৈরি করেন, হয় createComposeRule
অথবা, আপনার যদি কোনো কার্যকলাপে অ্যাক্সেসের প্রয়োজন হয়, createAndroidComposeRule
। রচনা করার জন্য একটি সাধারণ UI পরীক্ষা এইরকম দেখায়:
// file: app/src/androidTest/java/com/package/MyComposeTest.kt
class MyComposeTest {
@get:Rule val composeTestRule = createComposeRule()
// use createAndroidComposeRule<YourActivity>() if you need access to
// an activity
@Test
fun myTest() {
// Start the app
composeTestRule.setContent {
MyAppTheme {
MainScreen(uiState = fakeUiState, /*...*/)
}
}
composeTestRule.onNodeWithText("Continue").performClick()
composeTestRule.onNodeWithText("Welcome").assertIsDisplayed()
}
}
অতিরিক্ত সম্পদ
- অ্যান্ড্রয়েডে অ্যাপ পরীক্ষা করুন : প্রধান অ্যান্ড্রয়েড টেস্টিং ল্যান্ডিং পৃষ্ঠাটি পরীক্ষার মৌলিক বিষয় এবং কৌশলগুলির একটি বিস্তৃত দৃশ্য প্রদান করে।
- পরীক্ষার মৌলিক বিষয়গুলি : একটি Android অ্যাপ পরীক্ষা করার পিছনে মূল ধারণাগুলি সম্পর্কে আরও জানুন।
- স্থানীয় পরীক্ষা : আপনি আপনার নিজস্ব ওয়ার্কস্টেশনে স্থানীয়ভাবে কিছু পরীক্ষা চালাতে পারেন।
- ইন্সট্রুমেন্টেড পরীক্ষা : যন্ত্রযুক্ত পরীক্ষা চালানোও ভালো অভ্যাস। অর্থাৎ, যে পরীক্ষাগুলি সরাসরি ডিভাইসে চলে।
- ক্রমাগত ইন্টিগ্রেশন : ক্রমাগত ইন্টিগ্রেশন আপনাকে আপনার পরীক্ষাগুলিকে আপনার স্থাপনার পাইপলাইনে একত্রিত করতে দেয়।
- বিভিন্ন স্ক্রীনের মাপ পরীক্ষা করুন : ব্যবহারকারীদের জন্য উপলব্ধ কিছু অনেক ডিভাইসের সাথে, আপনার বিভিন্ন স্ক্রীন মাপের জন্য পরীক্ষা করা উচিত।
- এসপ্রেসো : ভিউ-ভিত্তিক UI-এর উদ্দেশ্যে, Espresso জ্ঞান এখনও রচনা পরীক্ষার কিছু দিকগুলির জন্য সহায়ক হতে পারে।
কোডল্যাব
আরও জানতে, জেটপ্যাক কম্পোজ টেস্টিং কোডল্যাব ব্যবহার করে দেখুন।
নমুনা
{% শব্দার্থে %}
{% endverbatim %} আপনার জন্য প্রস্তাবিত
{% শব্দার্থে %} {% endverbatim %}
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-08-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-08-27 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["Test your app's UI to verify that behavior of your Compose code is\ncorrect. This lets you catch errors early and improve the quality of your app.\n\nCompose provides a set of testing APIs to find elements, verify their\nattributes, and perform user actions. The APIs also include advanced features\nsuch as time manipulation. Use these APIs to create robust tests that verify\nyour app's behavior.\n| **Important:** For more on testing Android apps in general, including testing `View` elements, see the [general testing section](/training/testing). A good place to start is the [Fundamentals of testing Android apps](/training/testing/fundamentals) guide.\n\nViews\n\nIf you are working with views instead of Compose, see the general [Test apps on\nAndroid](/training/testing) section.\n\nIn particular, a good place to start is the [Automate UI tests](/training/testing/ui-tests) guide. It\nlays out how you can automate tests that run on-device, including when using\nviews.\n\nKey Concepts\n\nThe following are some key concepts for testing your Compose code:\n\n- **[Semantics](/develop/ui/compose/testing/semantics)**: Semantics give meaning to your UI, allowing tests to interact with specific elements.\n- **[Testing APIs](/develop/ui/compose/testing/apis)**: Testing APIs let you find elements, verify their attributes, and perform user actions.\n- **[Synchronization](/develop/ui/compose/testing/synchronization)**: Synchronization verifies that tests wait for the UI to be idle before performing actions or making assertions.\n- **[Interoperability](/develop/ui/compose/testing/interoperability)**: Interoperability enables tests to work with both Compose and View-based elements in the same app.\n\nTesting cheatsheet\n\nSee the [testing cheatsheet](/develop/ui/compose/testing/testing-cheatsheet) for an overview of all the key topics you should\nlearn about testing in Compose.\n\nSetup\n\nSet up your app to let you test compose code.\n\nFirst, add the following dependencies to the `build.gradle` file of the module\ncontaining your UI tests: \n\n // Test rules and transitive dependencies:\n androidTestImplementation(\"androidx.compose.ui:ui-test-junit4:$compose_version\")\n // Needed for createComposeRule(), but not for createAndroidComposeRule\u003cYourActivity\u003e():\n debugImplementation(\"androidx.compose.ui:ui-test-manifest:$compose_version\")\n\nThis module includes a [`ComposeTestRule`](/reference/kotlin/androidx/compose/ui/test/junit4/ComposeTestRule) and an implementation for Android\ncalled [`AndroidComposeTestRule`](/reference/kotlin/androidx/compose/ui/test/junit4/AndroidComposeTestRule). Through this rule you can set Compose\ncontent or access the activity. You construct the rules using factory functions,\neither [`createComposeRule`](/reference/kotlin/androidx/compose/ui/test/junit4/package-summary#createComposeRule()) or, if you need access to an activity,\n[`createAndroidComposeRule`](/reference/kotlin/androidx/compose/ui/test/junit4/package-summary#createAndroidComposeRule()). A typical UI test for Compose looks like this: \n\n // file: app/src/androidTest/java/com/package/MyComposeTest.kt\n\n class MyComposeTest {\n\n @get:Rule val composeTestRule = createComposeRule()\n // use createAndroidComposeRule\u003cYourActivity\u003e() if you need access to\n // an activity\n\n @Test\n fun myTest() {\n // Start the app\n composeTestRule.setContent {\n MyAppTheme {\n MainScreen(uiState = fakeUiState, /*...*/)\n }\n }\n\n composeTestRule.onNodeWithText(\"Continue\").performClick()\n\n composeTestRule.onNodeWithText(\"Welcome\").assertIsDisplayed()\n }\n }\n\nAdditional Resources\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.\n\nCodelab\n\nTo learn more, try the [Jetpack Compose Testing codelab](/codelabs/jetpack-compose-testing).\n\nSamples\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Semantics in Compose](/develop/ui/compose/semantics)\n- [Window insets in Compose](/develop/ui/compose/layouts/insets)\n- [Other considerations](/develop/ui/compose/migrate/other-considerations)"]]