Challenge - 5 Problems
Compose UI Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the output of this Compose UI test code?
Given the Compose UI test code below, what will the test verify successfully?
Android Kotlin
composeTestRule.setContent {
Button(onClick = {}) {
Text("Click Me")
}
}
composeTestRule.onNodeWithText("Click Me").assertIsDisplayed()Attempts:
2 left
💡 Hint
Look for the text inside the Button and what the test is asserting.
✗ Incorrect
The test sets a Button with text 'Click Me' and asserts that a node with this text is displayed. Since the text exists, the test passes.
❓ lifecycle
intermediate2:00remaining
What happens if you call composeTestRule.setContent twice in a test?
In a Compose UI test, what is the effect of calling setContent twice with different Composables?
Attempts:
2 left
💡 Hint
Think about how Compose manages UI content in tests.
✗ Incorrect
Calling setContent again replaces the previous UI content with the new Composable, so only the second UI is visible.
🔧 Debug
advanced2:00remaining
Why does this Compose test fail with NoMatchingNodeException?
This test fails with NoMatchingNodeException:
composeTestRule.setContent {
Text("Hello World")
}
composeTestRule.onNodeWithText("Hello").assertIsDisplayed()
Attempts:
2 left
💡 Hint
Check the exact text string used in the test and in the UI.
✗ Incorrect
The test looks for a node with exact text 'Hello', but the UI shows 'Hello World'. This mismatch causes NoMatchingNodeException.
advanced
2:30remaining
How to test navigation between two Compose screens?
You have two Composables: ScreenA and ScreenB. ScreenA has a button that navigates to ScreenB. Which test code correctly verifies navigation?
Android Kotlin
composeTestRule.setContent {
NavHost(navController, startDestination = "screenA") {
composable("screenA") { ScreenA(navController) }
composable("screenB") { ScreenB() }
}
}
composeTestRule.onNodeWithText("Go to B").performClick()
// What assertion verifies navigation?Attempts:
2 left
💡 Hint
After clicking the button, the UI should show ScreenB content.
✗ Incorrect
After performing click on the navigation button, the test should verify that ScreenB's content is displayed to confirm navigation.
🧠 Conceptual
expert3:00remaining
What is the role of Semantics in Compose UI testing?
Why is setting semantics properties important for Compose UI testing?
Attempts:
2 left
💡 Hint
Think about how tests identify UI elements beyond visible text.
✗ Incorrect
Semantics add descriptive information to UI elements, enabling tests to locate and interact with them reliably, especially when text is not unique or present.