عمليات التحقق وتنفيذ الإجراءات
تحقق من الحالة وحاكِ إدخال المستخدم
عمليات التحقق وتنفيذ الإجراءات درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Find, Then Verify
Finding a node is only half the job. To prove your UI behaves, you add an assertion that states what should be true about that node. ✅
assertIsDisplayed
The most common assertion is assertIsDisplayed. It confirms the node is actually visible to the user, not just present in the tree.
composeTestRule.onNodeWithText("Welcome")
.assertIsDisplayed()assertExists vs assertIsDisplayed
Watch the difference: assertExists checks the node is in the tree, while assertIsDisplayed also checks it is on screen and not clipped away.
composeTestRule.onNodeWithText("Footer")
.assertExists()Chaining Assertions
You can chain several checks on one node. Each returns the node again, so the test reads like a clear sentence about your UI state.
rule.onNodeWithText("Save")
.assertIsDisplayed()
.assertIsEnabled()Performing a Click
To simulate a tap, call performClick on a found node. Compose dispatches the same click your real users would trigger.
composeTestRule.onNodeWithText("Add")
.performClick()Typing Text
For input fields, performTextInput types characters into the focused field, letting you test forms exactly as a user would fill them.
rule.onNodeWithText("Email")
.performTextInput("a@b.com")Act, Then Assert
The classic flow is act then assert: perform a click, then verify the new state appeared. This mirrors how a person uses your app.
rule.onNodeWithText("+").performClick()
rule.onNodeWithText("Count: 1")
.assertIsDisplayed()Asserting on State Flags
Beyond visibility, you can check toggles. assertIsOn and assertIsOff verify switches and checkboxes hold the value you expect.
rule.onNodeWithText("Notifications")
.assertIsOff()Quick Check
You want to confirm a button is genuinely on screen, not merely present in the tree. Which assertion do you use?
Assert on Count
When you grab a group with onAllNodes, verify how many matched using assertCountEquals. It is perfect for checking list sizes.
rule.onAllNodesWithText("Item")
.assertCountEquals(3)Clear Before You Type
Replacing text? Call performTextClearance first, then performTextInput, so old characters do not stick around and break your check.
rule.onNodeWithText("Name")
.performTextClearance()Readable, Trustworthy Tests
Good assertions describe behavior, not pixels. Aim for tests that read like requirements, so a failure instantly tells you what behavior broke.
Recap: Actions & Assertions
You drive the UI with actions like performClick and performTextInput, then prove the result with assertions like assertIsDisplayed. That is the heart of UI testing. 🎯
الأسئلة الشائعة
هل درس «عمليات التحقق وتنفيذ الإجراءات» مجاني؟
نعم — نص درس «عمليات التحقق وتنفيذ الإجراءات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
ماذا ستتعلم في «عمليات التحقق وتنفيذ الإجراءات»؟
تحقق من الحالة وحاكِ إدخال المستخدم تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟
لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «عمليات التحقق وتنفيذ الإجراءات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟
نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- createComposeRule وأدوات البحث
- عمليات التحقق وتنفيذ الإجراءات
- الدلالات ووسوم الاختبار
- اختبار ViewModels والتدفقات