0Pricing
Jetpack Compose Academy · Lesson

Semantics & Test Tags

Make UI testable and accessible.

Semantics & Test Tags is a free Jetpack Compose Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. 🌳

Frequently asked questions

Is the “Semantics & Test Tags” lesson free?

Yes — the full text of “Semantics & Test Tags” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.

What will I learn in “Semantics & Test Tags”?

Make UI testable and accessible. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Jetpack Compose Academy?

No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Semantics & Test Tags” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Jetpack Compose Academy lesson?

Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. createComposeRule & Finders
  2. Assertions & Performing Actions
  3. Semantics & Test Tags
  4. Testing ViewModels & Flows
← Back to Jetpack Compose Academy