0Pricing
Jetpack Compose Academy · Lesson

Assertions & Performing Actions

Verify state and simulate user input.

Assertions & Performing Actions is a free Jetpack Compose Academy lesson on CoddyKit — lesson 2 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.

Find, Then Verify

Finding a node is only half the job. To prove your UI behaves, you add an assertion that states what should be true about that node. ✅

assertIsDisplayed

The most common assertion is assertIsDisplayed. It confirms the node is actually visible to the user, not just present in the tree.

composeTestRule.onNodeWithText("Welcome")
    .assertIsDisplayed()

assertExists vs assertIsDisplayed

Watch the difference: assertExists checks the node is in the tree, while assertIsDisplayed also checks it is on screen and not clipped away.

composeTestRule.onNodeWithText("Footer")
    .assertExists()

Chaining Assertions

You can chain several checks on one node. Each returns the node again, so the test reads like a clear sentence about your UI state.

rule.onNodeWithText("Save")
    .assertIsDisplayed()
    .assertIsEnabled()

Performing a Click

To simulate a tap, call performClick on a found node. Compose dispatches the same click your real users would trigger.

composeTestRule.onNodeWithText("Add")
    .performClick()

Typing Text

For input fields, performTextInput types characters into the focused field, letting you test forms exactly as a user would fill them.

rule.onNodeWithText("Email")
    .performTextInput("a@b.com")

Act, Then Assert

The classic flow is act then assert: perform a click, then verify the new state appeared. This mirrors how a person uses your app.

rule.onNodeWithText("+").performClick()
rule.onNodeWithText("Count: 1")
    .assertIsDisplayed()

Asserting on State Flags

Beyond visibility, you can check toggles. assertIsOn and assertIsOff verify switches and checkboxes hold the value you expect.

rule.onNodeWithText("Notifications")
    .assertIsOff()

Quick Check

You want to confirm a button is genuinely on screen, not merely present in the tree. Which assertion do you use?

Assert on Count

When you grab a group with onAllNodes, verify how many matched using assertCountEquals. It is perfect for checking list sizes.

rule.onAllNodesWithText("Item")
    .assertCountEquals(3)

Clear Before You Type

Replacing text? Call performTextClearance first, then performTextInput, so old characters do not stick around and break your check.

rule.onNodeWithText("Name")
    .performTextClearance()

Readable, Trustworthy Tests

Good assertions describe behavior, not pixels. Aim for tests that read like requirements, so a failure instantly tells you what behavior broke.

Recap: Actions & Assertions

You drive the UI with actions like performClick and performTextInput, then prove the result with assertions like assertIsDisplayed. That is the heart of UI testing. 🎯

Frequently asked questions

Is the “Assertions & Performing Actions” lesson free?

Yes — the full text of “Assertions & Performing Actions” 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 “Assertions & Performing Actions”?

Verify state and simulate user input. 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Assertions & Performing Actions” 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