อรรถศาสตร์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
การทดสอบ UI ใน Compose ใช้ความหมายเพื่อโต้ตอบกับลําดับชั้นของ UI
ความหมายตามชื่อจะให้ความหมายแก่ชิ้นส่วนของ UI ในบริบทนี้ "ชิ้นส่วนของ UI" (หรือองค์ประกอบ) อาจหมายถึงอะไรก็ได้ตั้งแต่ Composable รายการเดียวไปจนถึงทั้งหน้าจอ
แผนผังความหมายจะสร้างขึ้นควบคู่ไปกับลําดับชั้นของ UI และ
อธิบายลําดับชั้น
ดูข้อมูลเพิ่มเติมเกี่ยวกับความหมายโดยทั่วไปได้ในความหมายใน Compose
รูปที่ 1 ลำดับชั้น UI ทั่วไปและแผนผังความหมาย
โดยหลักๆ แล้วจะใช้เฟรมเวิร์กความหมายเพื่อการช่วยเหลือพิเศษ ดังนั้นการทดสอบจึงใช้ประโยชน์จากข้อมูลที่ความหมายเปิดเผยเกี่ยวกับลำดับชั้นของ UI
นักพัฒนาแอปเป็นผู้กำหนดว่าจะเปิดเผยข้อมูลใดและมากน้อยเพียงใด
รูปที่ 2 ปุ่มทั่วไปที่มีไอคอนและข้อความ
ตัวอย่างเช่น เมื่อพิจารณาปุ่มลักษณะนี้ซึ่งประกอบด้วยไอคอนและองค์ประกอบข้อความ
แผนภูมิต้นไม้เชิงความหมายเริ่มต้นจะมีป้ายกำกับข้อความ "ชอบ" เท่านั้น เนื่องจาก Composable บางรายการ เช่น Text
ได้แสดงคุณสมบัติบางอย่างต่อ
ต้นไม้ความหมายอยู่แล้ว คุณเพิ่มพร็อพเพอร์ตี้ลงในแผนผังความหมายได้โดยใช้
Modifier
MyButton(
modifier = Modifier.semantics { contentDescription = "Add to favorites" }
)
แหล่งข้อมูลเพิ่มเติม
- ทดสอบแอปใน Android: หน้า Landing Page หลักของการทดสอบ Android
จะให้มุมมองที่กว้างขึ้นเกี่ยวกับพื้นฐานและเทคนิคการทดสอบ
- หลักพื้นฐานของการทดสอบ: ดูข้อมูลเพิ่มเติม
เกี่ยวกับแนวคิดหลักเบื้องหลังการทดสอบแอป Android
- การทดสอบในเครื่อง: คุณสามารถเรียกใช้การทดสอบบางอย่าง
ในเครื่องบนเวิร์กสเตชันของคุณเองได้
- การทดสอบแบบมีเครื่องควบคุม: คุณควรเรียกใช้การทดสอบแบบมีเครื่องควบคุมด้วย กล่าวคือ การทดสอบที่ทำงานโดยตรง
ในอุปกรณ์
- การรวมอย่างต่อเนื่อง:
การรวมอย่างต่อเนื่องช่วยให้คุณผสานรวมการทดสอบเข้ากับไปป์ไลน์การติดตั้งใช้งานได้
- ทดสอบขนาดหน้าจอต่างๆ: เนื่องจากผู้ใช้มีอุปกรณ์ให้เลือกมากมาย คุณจึงควรทดสอบขนาดหน้าจอต่างๆ
- Espresso: แม้ว่า Espresso จะออกแบบมาสำหรับ UI ที่อิงตาม View แต่ความรู้เกี่ยวกับ Espresso ก็ยังเป็นประโยชน์สำหรับบางแง่มุมของการทดสอบ Compose
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 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-08-21 UTC"],[],[],null,["# Semantics\n\nUI tests in Compose use *semantics* to interact with the UI hierarchy.\nSemantics, as the name implies, give meaning to a piece of UI. In this context,\na \"piece of UI\" (or element) can mean anything from a single composable to a\nfull screen. The *semantics tree* is generated alongside the UI hierarchy and\ndescribes the hierarchy.\n\nYou can learn more about semantics generally in [Semantics in Compose](/develop/ui/compose/accessibility/semantics).\n\n**Figure 1.** A typical UI hierarchy and its semantics tree.\n\nThe semantics framework is primarily used for accessibility, so tests take\nadvantage of the information exposed by semantics about the UI hierarchy.\nDevelopers decide what and how much to expose.\n\n**Figure 2.** A typical button containing an icon and text.\n\nFor example, given a button like this that consists of an icon and a text\nelement, the default semantics tree only contains the text label \"Like\". This is\nbecause some composables, such as `Text`, already expose some properties to the\nsemantics tree. You can add properties to the semantics tree by using a\n`Modifier`. \n\n MyButton(\n modifier = Modifier.semantics { contentDescription = \"Add to favorites\" }\n )\n\nAdditional Resources\n--------------------\n\n- **[Test apps on Android](/training/testing)**: The main Android testing landing page provides a broader view of testing fundamentals and techniques.\n- **[Fundamentals of testing](/training/testing/fundamentals):** Learn more about the core concepts behind testing an Android app.\n- **[Local tests](/training/testing/local-tests):** You can run some tests locally, on your own workstation.\n- **[Instrumented tests](/training/testing/instrumented-tests):** It is good practice to also run instrumented tests. That is, tests that run directly on-device.\n- **[Continuous integration](/training/testing/continuous-integration):** Continuous integration lets you integrate your tests into your deployment pipeline.\n- **[Test different screen sizes](/training/testing/different-screens):** With some many devices available to users, you should test for different screen sizes.\n- **[Espresso](/training/testing/espresso)**: While intended for View-based UIs, Espresso knowledge can still be helpful for some aspects of Compose testing."]]