createComposeRule وأدوات البحث
أعد اختبار Compose وحدد مواضع العقد
createComposeRule وأدوات البحث درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Test Your UI?
Manual testing is slow and easy to forget. A UI test launches your Composable and checks it automatically, catching breakages before your users ever do. 🧪
Meet the Compose Test Rule
Every Compose test starts with a test rule. It hosts your Composables in a controlled environment so you can render, inspect, and interact with them from test code.
createComposeRule
For pure UI with no Activity, createComposeRule gives you a lightweight rule. You attach it as a JUnit @get:Rule field in your test class.
@get:Rule
val composeTestRule = createComposeRule()setContent in a Test
Use setContent on the rule to render the Composable you want to verify. This is your test's UI, just like in a real Activity.
composeTestRule.setContent {
Greeting(name = "Ada")
}Finders Locate Nodes
Once your UI is on screen, you need a finder to grab a specific element. Finders search the semantics tree and return a node you can assert on.
onNodeWithText
The friendliest finder is onNodeWithText. Give it the text shown on screen and it returns that exact node for you to check.
composeTestRule.onNodeWithText("Hello, Ada!")onNodeWithContentDescription
For images and icons with no visible text, use onNodeWithContentDescription. It matches the accessibility label, which keeps tests and screen readers in sync.
composeTestRule.onNodeWithContentDescription("Profile photo")One Node vs Many
onNode finds a single match and fails if there are several. When you expect a group of elements, reach for onAllNodes to get a collection instead.
composeTestRule.onAllNodesWithText("Item")Quick Check
You want to locate an icon button that has no visible text. Which finder fits best?
Finders Are Lazy
A finder does not search immediately. It captures your intent, and the actual lookup happens when you call an assertion or action on it.
Helpful Failure Messages
When a finder matches nothing, the test fails with a clear message and even prints the current node tree. That makes debugging a missing element fast.
createAndroidComposeRule
Need a real Activity, resources, or navigation? Swap in createAndroidComposeRule, which launches an Activity and still exposes the same finder API.
@get:Rule
val rule = createAndroidComposeRule<MainActivity>()Recap: Rules & Finders
You set up a compose rule, render with setContent, then locate elements with finders like onNodeWithText. That foundation powers every Compose test you write. 🎉
الأسئلة الشائعة
هل درس «createComposeRule وأدوات البحث» مجاني؟
نعم — نص درس «createComposeRule وأدوات البحث» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
ماذا ستتعلم في «createComposeRule وأدوات البحث»؟
أعد اختبار Compose وحدد مواضع العقد تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟
لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «createComposeRule وأدوات البحث»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟
نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- createComposeRule وأدوات البحث
- عمليات التحقق وتنفيذ الإجراءات
- الدلالات ووسوم الاختبار
- اختبار ViewModels والتدفقات