เอสเพรสโซ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ใช้ Espresso เพื่อเขียนการทดสอบ UI ของ Android ที่กระชับ สวยงาม และเชื่อถือได้
ข้อมูลโค้ดต่อไปนี้แสดงตัวอย่างของการทดสอบ Espresso
Kotlin
@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()))
}
Java
@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 หลักมีขนาดเล็ก คาดเดาได้ และเรียนรู้ได้ง่าย และยังเปิดกว้างสำหรับ
การปรับแต่งได้มากขึ้น เอสเพรสโซทดสอบความคาดหวัง การโต้ตอบ และการยืนยันสถานะ
โดยไม่มีสิ่งรบกวนจากเนื้อหาสำเร็จรูป โครงสร้างพื้นฐานที่กำหนดเอง
หรือรายละเอียดการนำไปใช้ที่ไม่เป็นระเบียบ
การทดสอบเอสเพรสโซ่จะทำงานอย่างมีประสิทธิภาพสูงสุด ช่วยให้คุณไม่ต้องรอ ซิงค์ นอนหลับ
และโพลที่อยู่เบื้องหลังขณะ
ปรับแต่งและยืนยันในแอปพลิเคชัน
UI เมื่อไม่มีการใช้งาน
กลุ่มเป้าหมาย
Espresso กำหนดเป้าหมายไปยังนักพัฒนาซอฟต์แวร์ ซึ่งเชื่อว่าการทดสอบอัตโนมัติเป็น
เป็นส่วนสำคัญของวงจรการพัฒนา ในขณะที่สามารถใช้กับกล่องดำได้
ความสามารถเต็มรูปแบบของ Espresso จะปลดล็อกได้โดยผู้ที่คุ้นเคยกับ
ฐานของโค้ดอยู่
ภายใต้การทดสอบ
ความสามารถในการซิงค์
ทุกครั้งที่มีการเรียกใช้การทดสอบ
onView()
Espresso รอให้ดำเนินการหรือการยืนยัน UI ที่เกี่ยวข้องจนกระทั่ง
ตรงกับเงื่อนไขการซิงค์ข้อมูลต่อไปนี้
- คิวข้อความไม่มีข้อความที่ Espresso จำเป็นต้องกระทำทันที
ขั้นตอนได้
- ไม่มีอินสแตนซ์ของ
AsyncTask
ที่กำลังดำเนินการอยู่ในขณะนี้
งาน
- กำหนดโดยนักพัฒนาแอปทั้งหมด
ทรัพยากรที่ไม่ได้ใช้งาน
การดำเนินการตรวจสอบเหล่านี้ ทำให้ Espresso เพิ่มความเป็นไปได้อย่างมากที่
จะมีการดำเนินการหรือการยืนยันสำหรับ UI ได้เพียงรายการเดียวในช่วงเวลาหนึ่งๆ ความสามารถนี้
ทำให้ผลการทดสอบมีความน่าเชื่อถือและน่าเชื่อถือมากขึ้น
แพ็กเกจ
espresso-core
- มีตัวจับคู่ การดำเนินการ และ View
หลักและพื้นฐาน
การยืนยันของคุณ โปรดดู
พื้นฐาน
และ Recipes
espresso-web
- มีทรัพยากรสำหรับการสนับสนุนของ WebView
espresso-idling-resource
กลไกของ Espresso สำหรับการซิงค์ข้อมูลกับงานที่ทำอยู่เบื้องหลัง
espresso-contrib
- การสนับสนุนภายนอกที่มี DatePicker
,
การดำเนินการ RecyclerView
และ Drawer
การตรวจสอบการช่วยเหลือพิเศษ และ
CountingIdlingResource
espresso-intents
การขยายเวลาเพื่อตรวจสอบและระงับความตั้งใจสำหรับการทดสอบแบบแยกต่างหาก
espresso-remote
- ตำแหน่งของฟังก์ชันการประมวลผลแบบหลากหลายของ Espresso
คุณสามารถเรียนรู้เพิ่มเติมเกี่ยวกับเวอร์ชันล่าสุดได้โดยอ่าน
บันทึกประจำรุ่น
แหล่งข้อมูลเพิ่มเติม
หากต้องการข้อมูลเพิ่มเติมเกี่ยวกับการใช้ Espresso ในการทดสอบ Android โปรดดู
แหล่งข้อมูลต่อไปนี้
ตัวอย่าง
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","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-27 UTC"],[],[],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)"]]