اسپرسو
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
از اسپرسو برای نوشتن تست های مختصر، زیبا و قابل اعتماد رابط کاربری اندروید استفاده کنید.
قطعه کد زیر نمونه ای از تست اسپرسو را نشان می دهد:
کاتلین
@Test
fun greeterSaysHello() {
onView(withId(R.id.name_field)).perform(typeText("Steve"))
onView(withId(R.id.greet_button)).perform(click())
onView(withText("Hello Steve!")).check(matches(isDisplayed()))
}
جاوا
@Test
public void greeterSaysHello() {
onView(withId(R.id.name_field)).perform(typeText("Steve"));
onView(withId(R.id.greet_button)).perform(click());
onView(withText("Hello Steve!")).check(matches(isDisplayed()));
}

API اصلی کوچک، قابل پیشبینی و یادگیری آسان است و در عین حال برای سفارشیسازی باز است. اسپرسو انتظارات، فعل و انفعالات و اظهارات دولت را به وضوح بدون حواس پرتی محتوای دیگ بخار، زیرساخت های سفارشی یا جزئیات اجرای آشفته آزمایش می کند.
تست اسپرسو با سرعت بهینه اجرا می شود! این به شما امکان میدهد انتظارها، همگامسازیها، خوابها و نظرسنجیهای خود را در زمانی که رابط کاربری برنامه در حالت استراحت است دستکاری و اظهارنظر کند، پشت سر بگذارید.
مخاطب هدف
اسپرسو توسعه دهندگانی را هدف قرار داده است که معتقدند تست خودکار بخشی جدایی ناپذیر از چرخه عمر توسعه است. در حالی که می توان از آن برای تست جعبه سیاه استفاده کرد، قدرت کامل اسپرسو توسط کسانی که با پایگاه کد مورد آزمایش آشنا هستند باز می شود.
قابلیت های همگام سازی
هر بار که تست شما onView()
را فراخوانی میکند، اسپرسو منتظر میماند تا عمل یا ادعای UI مربوطه را انجام دهد تا شرایط همگامسازی زیر برآورده شود:
- صف پیام هیچ پیامی ندارد که اسپرسو باید فوراً آنها را پردازش کند.
- هیچ نمونهای از
AsyncTask
در حال اجرای یک کار وجود ندارد. - همه منابع غیرفعال تعریف شده توسط توسعه دهندگان بیکار هستند.
با انجام این بررسیها، اسپرسو به طور قابل ملاحظهای این احتمال را افزایش میدهد که تنها یک اقدام یا ادعای UI در هر زمان معین رخ دهد. این قابلیت نتایج تست قابل اعتمادتر و قابل اعتمادتری را به شما می دهد.
بسته ها
-
espresso-core
- شامل View
، اقدامات و ادعاهای اصلی و اصلی است. به اصول و دستور العمل ها مراجعه کنید. -
espresso-web
- حاوی منابعی برای پشتیبانی WebView
است. -
espresso-idling-resource
- مکانیسم اسپرسو برای همگام سازی با مشاغل پس زمینه. -
espresso-contrib
- مشارکتهای خارجی که شامل اقدامات DatePicker
، RecyclerView
و Drawer
، بررسیهای دسترسی، و CountingIdlingResource
هستند. -
espresso-intents
- برنامه افزودنی برای تأیید اعتبار و مقاصد خرد برای آزمایش هرمتیک. -
espresso-remote
- محل عملکرد چند فرآیندی اسپرسو.
با خواندن یادداشت های انتشار می توانید درباره آخرین نسخه ها اطلاعات بیشتری کسب کنید.
منابع اضافی
برای اطلاعات بیشتر در مورد استفاده از اسپرسو در تست های اندروید به منابع زیر مراجعه کنید.
نمونه ها
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و 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,["# Espresso\n\nUse Espresso to write concise, beautiful, and reliable Android UI tests.\n\nThe following code snippet shows an example of an Espresso test:\n\n\u003cbr /\u003e\n\n### Kotlin\n\n```kotlin\n@Test\nfun greeterSaysHello() {\n onView(withId(R.id.name_field)).perform(typeText(\"Steve\"))\n onView(withId(R.id.greet_button)).perform(click())\n onView(withText(\"Hello Steve!\")).check(matches(isDisplayed()))\n}\n```\n\n### Java\n\n```java\n@Test\npublic void greeterSaysHello() {\n onView(withId(R.id.name_field)).perform(typeText(\"Steve\"));\n onView(withId(R.id.greet_button)).perform(click());\n onView(withText(\"Hello Steve!\")).check(matches(isDisplayed()));\n}\n```\n\n\u003cbr /\u003e\n\nThe core API is small, predictable, and easy to learn and yet remains open for\ncustomization. Espresso tests state expectations, interactions, and assertions\nclearly without the distraction of boilerplate content, custom infrastructure,\nor messy implementation details getting in the way.\n\nEspresso tests run optimally fast! It lets you leave your waits, syncs, sleeps,\nand polls behind while it manipulates and asserts on the application\nUI when it is at rest.\n\nTarget audience\n---------------\n\nEspresso is targeted at developers, who believe that automated testing is an\nintegral part of the development lifecycle. While it can be used for black-box\ntesting, Espresso's full power is unlocked by those who are familiar with the\ncodebase under test.\n\nSynchronization capabilities\n----------------------------\n\nEach time your test invokes\n[`onView()`](/reference/androidx/test/espresso/Espresso#onView(org.hamcrest.Matcher%3Candroid.view.View%3E)),\nEspresso waits to perform the corresponding UI action or assertion until the\nfollowing synchronization conditions are met:\n\n- The message queue doesn't have any messages that Espresso needs to immediately process.\n- There are no instances of [AsyncTask](/reference/android/os/AsyncTask) currently executing a task.\n- All developer-defined [idling resources](/training/testing/espresso/idling-resource) are idle.\n\nBy performing these checks, Espresso substantially increases the likelihood that\nonly one UI action or assertion can occur at any given time. This capability\ngives you more reliable and dependable test results.\n\nPackages\n--------\n\n- `espresso-core` - Contains core and basic `View` matchers, actions, and assertions. See [Basics](/training/testing/espresso/basics) and [Recipes](/training/testing/espresso/recipes).\n- [`espresso-web`](/training/testing/espresso/web) - Contains resources for `WebView` support.\n- [`espresso-idling-resource`](/training/testing/espresso/idling-resource) - Espresso's mechanism for synchronization with background jobs.\n- `espresso-contrib` - External contributions that contain `DatePicker`, `RecyclerView` and `Drawer` actions, accessibility checks, and `CountingIdlingResource`.\n- [`espresso-intents`](/training/testing/espresso/intents) - Extension to validate and stub intents for hermetic testing.\n- `espresso-remote` - Location of Espresso's [multi-process](/training/testing/espresso/multiprocess) functionality.\n\nYou can learn more about the latest versions by reading the\n[release notes](/topic/libraries/testing-support-library/release-notes).\n\nAdditional resources\n--------------------\n\nFor more information about using Espresso in Android tests, consult the\nfollowing resources.\n\n### Samples\n\n- [Espresso Code Samples](https://github.com/googlesamples/android-testing) includes a full selection of Espresso samples.\n- [BasicSample](https://github.com/android/testing-samples/tree/main/ui/espresso/BasicSample): Basic Espresso sample.\n- [(more...)](/training/testing/espresso/additional-resources#samples)"]]