การทดสอบ UI ลักษณะการทำงาน
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การทดสอบ UI ลักษณะการทำงานเป็นการทดสอบที่จะวิเคราะห์ลำดับชั้น UI เพื่อยืนยันคุณสมบัติขององค์ประกอบ UI
เฟรมเวิร์ก Jetpack
Jetpack มีเฟรมเวิร์กมากมายที่มี API สำหรับการเขียนการทดสอบ UI ดังนี้
- เฟรมเวิร์กการทดสอบ Espresso (Android 4.0.1, API ระดับ 14 ขึ้นไป) มี API สําหรับการเขียนการทดสอบ UI เพื่อจําลองการโต้ตอบของผู้ใช้กับ Views ภายในแอปเป้าหมายแอปเดียว ข้อดีที่สําคัญของการใช้ Espresso คือมีการซิงค์การดําเนินการทดสอบกับ UI ของแอปที่คุณทดสอบโดยอัตโนมัติ Espresso จะตรวจจับเมื่อเทรดหลักไม่มีการใช้งาน เพื่อที่จะเรียกใช้คำสั่งทดสอบในเวลาที่เหมาะสม ซึ่งจะช่วยเพิ่มความน่าเชื่อถือของการทดสอบ
- Jetpack Compose (Android 5.0, API ระดับ 21 ขึ้นไป) มีชุดAPI การทดสอบเพื่อเปิดใช้งานและโต้ตอบกับหน้าจอและคอมโพเนนต์ Compose การโต้ตอบกับองค์ประกอบ "Compose" จะซิงค์กับการทดสอบและควบคุมช่วงเวลา ภาพเคลื่อนไหว และการจัดองค์ประกอบใหม่ได้อย่างสมบูรณ์
- UI Automator (Android 4.3, API ระดับ 18 ขึ้นไป) เป็นเฟรมเวิร์กการทดสอบ UI ที่เหมาะสำหรับการทดสอบ UI ฟังก์ชันการทำงานข้ามแอปในระบบและแอปที่ติดตั้ง API Automator ของ UI ให้คุณดำเนินการต่างๆ เช่น การเปิดเมนูการตั้งค่าหรือตัวเปิดแอปในอุปกรณ์ทดสอบ
- Robolectric (Android 4.1, API ระดับ 16 ขึ้นไป) ช่วยให้คุณสร้างการทดสอบในเครื่องที่ทำงานบนเวิร์กสเตชันหรือสภาพแวดล้อมการผสานรวมอย่างต่อเนื่องใน JVM ปกติแทนที่จะทำงานบนโปรแกรมจำลองหรืออุปกรณ์ โดยสามารถใช้ Espresso หรือ Compose Testing API เพื่อโต้ตอบกับคอมโพเนนต์ UI ได้
แหล่งข้อมูลเพิ่มเติม
ดูข้อมูลเพิ่มเติมเกี่ยวกับการสร้างการทดสอบ UI ได้ที่แหล่งข้อมูลต่อไปนี้
เอกสารประกอบ
Codelabs
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา 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,["# 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)"]]