0Pricing
Jetpack Compose Academy · บทเรียน

ความหมายและแท็กการทดสอบ

ทำให้ส่วนติดต่อผู้ใช้ทดสอบได้และเข้าถึงได้

ความหมายและแท็กการทดสอบ เป็นบทเรียน Jetpack Compose Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Jetpack Compose Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Semantics Tree

Compose builds a semantics tree next to the visual one. It describes what each element means, and it is exactly what both tests and screen readers read.

Why Semantics Matter

If a node carries no meaning in the tree, finders cannot reach it and TalkBack cannot announce it. Good semantics make your app both testable and accessible. ♿

Content Descriptions Add Meaning

Icons and images carry no text, so give them a contentDescription. It feeds the semantics tree, letting tests find them and screen readers describe them.

Icon(Icons.Default.Add,
    contentDescription = "Add item")

When Text Is Not Unique

Sometimes many nodes share the same text and a text finder gets confused. You need a stable handle that does not depend on the visible label.

Introducing testTag

A testTag is an invisible identifier you attach with a Modifier. It gives a node a unique name for tests without affecting how it looks.

Box(Modifier.testTag("avatar"))

Finding by Tag

Once tagged, locate the node with onNodeWithTag. This is rock-solid even when text changes across languages or states.

composeTestRule.onNodeWithTag("avatar")
    .assertIsDisplayed()

Quick Check

Several buttons share the label Done, so a text finder is ambiguous. What gives one button a unique, invisible handle for tests?

Tags vs Descriptions

Keep them separate: contentDescription serves real users, while testTag exists only for tests. Do not overload one to do the other's job.

The semantics Modifier

For full control, the semantics modifier lets you set custom properties, like marking a node as a heading for accessibility tools.

Modifier.semantics { heading() }

Merging Descendants

Compose can merge a parent and its children into one node with mergeDescendants. That makes a whole row announce as a single, friendly unit.

Modifier.semantics(mergeDescendants = true) {}

Print the Tree to Debug

Stuck on a missing node? Call printToLog on the root to dump the full semantics tree, then read exactly what is available to match.

rule.onRoot().printToLog("TREE")

Design for Testability

Adding clear descriptions and tags as you build means your tests almost write themselves. Accessible apps and testable apps grow from the same habits.

Recap: Semantics & Tags

The semantics tree powers both testing and accessibility. Use contentDescription for users and testTag for tests to keep your UI easy to verify. 🌳

คำถามที่พบบ่อย

บทเรียน “ความหมายและแท็กการทดสอบ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ความหมายและแท็กการทดสอบ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Jetpack Compose Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Jetpack Compose Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ความหมายและแท็กการทดสอบ”

ทำให้ส่วนติดต่อผู้ใช้ทดสอบได้และเข้าถึงได้ คุณปฏิบัติ Jetpack Compose Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Jetpack Compose Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Jetpack Compose Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “ความหมายและแท็กการทดสอบ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Jetpack Compose Academy นี้ได้ไหม

ได้ บทเรียน Jetpack Compose Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. createComposeRule และตัวค้นหา
  2. การตรวจสอบและการดำเนินการ
  3. ความหมายและแท็กการทดสอบ
  4. การทดสอบ ViewModels และ Flow
← กลับไปที่ Jetpack Compose Academy