تست های رابط کاربری رفتار
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
تستهای رفتار UI تستهایی هستند که سلسلهمراتب UI را تجزیه و تحلیل میکنند تا در مورد ویژگیهای عناصر UI اظهارنظر کنند.
چارچوب های جت پک
Jetpack شامل چارچوب های مختلفی است که API هایی را برای نوشتن تست های UI ارائه می کند:
- چارچوب تست اسپرسو (Android 4.0.1، API سطح 14 یا بالاتر) APIهایی را برای نوشتن تستهای UI برای شبیهسازی تعاملات کاربر با Views در یک برنامه هدف فراهم میکند. یکی از مزایای کلیدی استفاده از اسپرسو این است که همگام سازی خودکار اقدامات آزمایشی با رابط کاربری برنامه ای که در حال آزمایش آن هستید را فراهم می کند. اسپرسو تشخیص می دهد که نخ اصلی بیکار است، بنابراین می تواند دستورات تست شما را در زمان مناسب اجرا کند و قابلیت اطمینان تست های شما را بهبود می بخشد.
- Jetpack Compose (Android 5.0، API سطح 21 یا بالاتر) مجموعهای از APIهای آزمایشی را برای راهاندازی و تعامل با صفحهها و اجزای Compose ارائه میکند. تعامل با عناصر Compose با تستها هماهنگ شده و کنترل کاملی بر زمان، انیمیشنها و ترکیببندیها دارد.
- UI Automator (اندروید 4.3، API سطح 18 یا بالاتر) یک چارچوب آزمایشی UI است که برای آزمایش UI کاربردی بین برنامهای در سراسر سیستم و برنامههای نصب شده مناسب است. رابط های برنامه کاربردی UI Automator به شما امکان می دهد عملیات هایی مانند باز کردن منوی تنظیمات یا راه اندازی برنامه را در یک دستگاه آزمایشی انجام دهید.
- Robolectric (اندروید 4.1، API سطح 16 یا بالاتر) به شما امکان میدهد به جای شبیهساز یا دستگاه، آزمایشهای محلی را ایجاد کنید که روی ایستگاه کاری یا محیط یکپارچهسازی مداوم شما در یک JVM معمولی اجرا شوند. میتواند از APIهای تست Espresso یا Compose برای تعامل با اجزای UI استفاده کند.
منابع اضافی
برای اطلاعات بیشتر در مورد ایجاد تست های رابط کاربری، به منابع زیر مراجعه کنید.
مستندات
Codelabs
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Behavior UI Tests\n\nBehavior UI tests are tests that analyze the UI hierarchy to make assertions\non the properties of the UI elements.\n\nJetpack frameworks\n------------------\n\nJetpack includes various frameworks that provide APIs for writing UI tests:\n\n- The **[Espresso testing framework](/training/testing/espresso)** (Android 4.0.1, API level 14 or higher) provides APIs for writing UI tests to simulate user interactions with *Views* within a single target app. A key benefit of using Espresso is that it provides automatic synchronization of test actions with the UI of the app you are testing. Espresso detects when the main thread is idle, so it is able to run your test commands at the appropriate time, improving the reliability of your tests.\n- **[Jetpack Compose](/jetpack/compose)** (Android 5.0, API level 21 or higher) provides a set of [*testing APIs*](/jetpack/compose/testing) to launch and interact with Compose screens and components. Interactions with Compose elements are synchronized with tests and have complete control over time, animations and recompositions.\n- **[UI Automator](/training/testing/ui-automator)** (Android 4.3, API level 18 or higher) is a UI testing framework suitable for cross-app functional UI testing across system and installed apps. The UI Automator APIs allows you to perform operations such as opening the Settings menu or the app launcher on a test device.\n- **[Robolectric](/training/testing/local-tests/robolectric)** (Android 4.1, API level 16 or higher) lets you create *local* tests that run on your workstation or continuous integration environment in a regular JVM, instead of on an emulator or device. It can use Espresso or Compose testing APIs to interact with UI components.\n\nAdditional resources\n--------------------\n\nFor more information about creating UI tests, consult the following resources.\n\n### Documentation\n\n- [Build instrumented tests](/training/testing/instrumented-tests)\n- [Espresso](/training/testing/espresso)\n- [Compose Testing](/jetpack/compose/testing)\n\n### Codelabs\n\n- [Introduction to Test Doubles and Dependency Injection](/codelabs/advanced-android-kotlin-training-testing-test-doubles)"]]