اختبِر واجهة المستخدم لتطبيقك للتحقق من صحة سلوك رمز Compose. ويتيح لك ذلك اكتشاف الأخطاء مبكرًا وتحسين جودة تطبيقك.
توفّر Compose مجموعة من واجهات برمجة التطبيقات لاختبار العثور على العناصر والتحقّق من سماتها وتنفيذ إجراءات المستخدم. تتضمّن واجهات برمجة التطبيقات أيضًا ميزات متقدّمة، مثل التحكّم في الوقت. استخدم واجهات برمجة التطبيقات هذه لإنشاء اختبارات قوية تتحقق من سلوك تطبيقك.
المشاهدات
إذا كنت تستخدم الملفات الشخصية بدلاً من ميزة "إنشاء"، يُرجى الاطّلاع على القسم العام اختبار التطبيقات على Android.
على وجه الخصوص، يمكنك البدء بدليل اختبارات واجهة المستخدم المبرمَجة. ويوضّح هذا القسم كيفية برمجة الاختبارات التي يتم إجراؤها على الجهاز، بما في ذلك عند استخدام طرق العرض.
المفاهيم الرئيسية
في ما يلي بعض المفاهيم الأساسية لاختبار رمز Compose.
- الدلالات: تتفاعل اختبارات الإنشاء مع واجهة المستخدم باستخدام الدلالات، التي تمنح معنى لقطع واجهة المستخدم ويتم إنشاؤها إلى جانب التسلسل الهرمي لواجهة المستخدم.
- اختبار واجهات برمجة التطبيقات: توفّر أداة Compose واجهات برمجة تطبيقات للاختبار للعثور على العناصر، وإجراء تأكيدات على حالتها وخصائصها، وتنفيذ إجراءات لمحاكاة تفاعلات المستخدمين.
- المزامنة: تتم تلقائيًا مزامنة اختبارات Compose مع واجهة المستخدم، في انتظار أن تصبح غير نشِطة قبل إجراء التأكيدات أو تنفيذ الإجراءات.
- إمكانية التشغيل التفاعلي: في التطبيقات المختلطة، يمكن أن تتفاعل الاختبارات بسلاسة مع كل من العناصر المستندة إلى الإنشاء والعرض، والتكامل مع أطر الاختبار الأخرى.
بطاقة معلومات اختبارية
اطّلِع على ملخّص الاختبار للحصول على نظرة عامة على جميع المواضيع الرئيسية التي يجب التعرّف عليها حول الاختبار في Compose.
ضبط إعدادات الجهاز
إعداد تطبيقك للسماح لك باختبار رمز الإنشاء
أولاً، أضِف التبعيات التالية إلى ملف 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")
تتضمّن هذه الوحدة ComposeTestRule
وعملية تنفيذ لنظام Android باسم AndroidComposeTestRule
. ومن خلال هذه القاعدة، يمكنك تعيين إنشاء
محتوى أو الوصول إلى النشاط. يمكنك إنشاء القواعد باستخدام وظائف المصنع،
إما createComposeRule
أو، إذا كنت بحاجة إلى الوصول إلى نشاط،
createAndroidComposeRule
. يبدو الاختبار النموذجي لواجهة المستخدم في Compose على النحو التالي:
// 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: تقدّم الصفحة المقصودة الرئيسية لاختبار Android نظرة أوسع على أساسيات الاختبار وأساليبه.
- أساسيات الاختبار: اطّلِع على مزيد من المعلومات عن المفاهيم الأساسية لاختبار تطبيق Android.
- الاختبارات المحلية: يمكنك إجراء بعض الاختبارات محليًا على محطة عملك.
- الاختبارات المستندة إلى الأدوات: من الممارسات الجيدة إجراء الاختبارات المستندة إلى الأدوات أيضًا. وهذا يعني الاختبارات التي يتم إجراؤها على الجهاز مباشرةً.
- الدمج المستمر: يتيح لك الدمج المستمر دمج اختباراتك في مسار النشر.
- اختبار أحجام الشاشات المختلفة: مع توفّر بعض الأجهزة العديدة للمستخدمين، عليك اختبار أحجام الشاشات المختلفة.
- Espresso: على الرغم من أنّ Espresso مخصّص لواجهات مستنِدة إلى الاطّلاع، يمكن أن تكون المعرفة به مفيدة لبعض جوانب اختبار ميزة "الإنشاء".
الدرس التطبيقي حول الترميز
لمزيد من المعلومات، يمكنك تجربة الدليل التعليمي لاختبار Jetpack Compose.
نماذج
تتيح Microsoft للمستخدمين والمؤسسات العمل والتعلّم والتنظيم والتواصل والابتكار من خلال تطبيقاتهم الرائدة في Microsoft 365. ولتحقيق ذلك، تدرك الشركة أنّه من الضروري توفير تجربة إنتاجية مثالية لعملائها على جميع الأجهزة التي يستخدمونها. تساعد منصّة Square ملايين البائعين في إدارة
نشاطك التجاري، بدءًا من المعالجة الآمنة لبطاقات الائتمان ووصولاً إلى حلول نقاط البيع
إعداد متجر مجاني على الإنترنت. تم نقل المربع إلى واجهة المستخدم التعريفية
لفترة من الوقت ولكن بدلاً من الاستمرار في بناء Monzo هو مصرف وتطبيق يقدّمان
الخدمات المالية الرقمية. مهمتهم هي تحقيق الأرباح
للجميع. بدأ نظام تصميم مونزو ينحرف عن Material Design بحيث
أرادوا طريقة سهلة لكتابة المكوّنات المخصصة وصيانتها تتطوّر باستمرار، لذا اختارت Jetpack Compose. باستخدام منصة Twitter هي واحدة من أكثر وسائل التواصل الاجتماعي استخدامًا
ومنصات الوسائط التي تتيح للمستخدمين رؤية ما يحدث في العالم في أي وقت
اللحظة. بدأ الفريق الهندسي باستخدام Jetpack Compose لتجديد
نظام التصميم. بما أنّه تم تطوير مكونات واجهة المستخدم شركة Cuvva تحسّن التأمين بشكل كبير
من خلال منحك طريقة مرنة حقًا لإدارة الغلاف، كل ذلك من خلال هاتفك.
كان على مهندسي Android في Cuvva قضاء بعض الوقت في إعادة هندسة تطبيقاتهم
وقررت اعتماد تدفق بيانات أحادي الاتجاه وJetpack Compose. بهذه الطريقة
يمكنهم ShareChat is a leading social media platform in India that allows users to share their opinions, document their lives, and make new friends in their native language. The standard Red Up Green Down color scheme that many wealth management app users take for granted can be very problematic for colorblind users and those with color vision deficiency.The Futubull team is embracing users’ needs by making concrete improvements so that everyone can grasp the key to wealth. TikTok, the world’s community-driven entertainment destination, brings over 1 billion people together from around the world to discover, create and share content they love. OkCredit is a credit account management app for millions of shop owners and their customers in India. With 140M transactions month over month, and 50M+ downloads, last year alone saw OkCredit recording $50 billion worth of transactions on the app. Operating at such a huge scale scale, OkCredit created a smooth and seamless experience for all their users by focusing on reducing ANRs and improving the app startup time. Lyft is committed to app excellence. They have to be. For a rideshare app — providing a vital, time-sensitive service to millions of drivers and riders every day — a slow or unresponsive app adds unacceptable friction. Josh is a short-video app from India, launched in 2020. One of the fastest growing short-video apps with over 124 million MAUs, optimizing it across a range of devices (high, mid, low end) and maintaining a standard experience across all of them is critical for their success. Improving app startups time and making the app responsive helped them achieve success. Microsoft Lens increases developer productivity using CameraX Zomato is an Indian multinational restaurant aggregator and food delivery company serving customers across 500 cities in India alone. In order to launch new features on their Android app, Headspace spent 8 months refactoring their architecture and rewriting in Kotlin. Learn how this reboot helped their business grow. Google Photos is the home for your memories, and their development team believes people should be able to enjoy those memories across all devices. Learn how Duolingo made the business decision to focus on Android performance and how they improved developer productivity and scaled their business. Mercari allows millions of people to shop and sell almost anything. The company was founded in 2013 in Japan, and it now is the largest smartphone-focused C2C marketplace in Japan. Google Duo is a simple, high quality video calling app for everyone. With the increase of people being at home during the Covid-19 pandemic, the Duo team saw a significant increase in people using the app to stay connected with friends & family, school and work. Headspace drive business growth by investing in Android app quality. SmartNews helps millions of people discover their world everyday by sharing timely news from a diverse set of news sources. Twitter is one of the most widely used social media platforms where users can see what’s happening in the world at any given moment. Delight Room Alarmy is an alarm app that can be turned off only when the pre-selected activities, such as taking a photo, solving a math problem, shaking phone, etc., are performed by the user. The Google Home app helps set up, manage, and control your Google Home, Google Nest, and Chromecast devices—plus thousands of connected home products like lights, cameras, thermostats, and more. Truecaller is an app that offers caller identification, call blocking, chat messaging and organized inbox. The app has a basic offering and a premium version which is ad-free and has a variety of unlocked features like advanced spam blocking and call recording.تمكّنت Microsoft Outlook وTeams وOffice من زيادة عدد المستخدمين النشطين والاحتفاظ بالمستخدمين باستخدام الشاشات الكبيرة.
يحقّق المربع زيادة في الإنتاجية باستخدام Compose
تنشئ Monzo تطبيقًا أكثر فعالية وجودة باستخدام Compose
شركة Twitter تحقّق زيادة في كفاءة وسرعة المطوّرين باستخدام Compose
تنشئ شركة Cuvva أكثر سرعة وبجودة أعلى من خلال Compose.
ShareChat addresses Jank issues to increase feed scrolling by 60%
The Key to Wealth for Everyone
TikTok Optimizes User Experience with Android Tools
OkCredit’s average merchant transaction goes up by 30% after reducing ANR
Lyft improves Android app startup time for drivers by 21%
Josh sees increased customer retention by improving app startup time by 30%
Microsoft Lens increases developer productivity using CameraX
Increasing app speed by 30%: a key ingredient in Zomato’s growth recipe
Headspace's Android reboot increases monthly active users by 15%
Google Photos increased daily active users by building for large screens
Duolingo refactors on Android with MVVM and Jetpack libraries
Mercari improves UI development productivity by 56% with Jetpack Compose
Google Duo sees increased engagement and improved ratings by optimizing for larger screens
Headspace drive business growth by investing in Android app quality
SmartNews reduces lines of code by 20% and improves team morale with Kotlin
Twitter increases developer productivity and code reliability with Kotlin
Delight Room increased 90% of its organic US users with Play Console
Google Home reduces #1 cause of crashes by 33%
Truecaller brings ~40% subscribers back with real time developer notifications
ما من اقتراحات في الوقت الحالي.
يُرجى محاولة تسجيل الدخول إلى حسابك على Google.