0
0
Android Kotlinmobile~20 mins

Compose UI testing in Android Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Compose UI Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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()
AThe test fails because the text 'Click Me' is not found in the UI.
BThe test fails because the button has no click action defined.
CThe test passes because the button with text 'Click Me' is displayed.
DThe test passes but does not check if the button is clickable.
Attempts:
2 left
💡 Hint
Look for the text inside the Button and what the test is asserting.
lifecycle
intermediate
2: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?
AThe second setContent replaces the first UI content completely.
BBoth Composables are shown simultaneously on the screen.
CThe test will crash due to multiple setContent calls.
DThe first Composable remains visible and the second is ignored.
Attempts:
2 left
💡 Hint
Think about how Compose manages UI content in tests.
🔧 Debug
advanced
2:00remaining
Why does this Compose test fail with NoMatchingNodeException?
This test fails with NoMatchingNodeException: composeTestRule.setContent { Text("Hello World") } composeTestRule.onNodeWithText("Hello").assertIsDisplayed()
AThe test fails because assertIsDisplayed is not a valid assertion.
BThe test fails because the Text composable is not clickable.
CThe test fails because setContent was not called on the main thread.
DThe text 'Hello' does not exactly match 'Hello World', so no node is found.
Attempts:
2 left
💡 Hint
Check the exact text string used in the test and in the UI.
navigation
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?
AcomposeTestRule.onNodeWithText("Screen B Content").assertIsDisplayed()
BcomposeTestRule.onNodeWithText("Go to B").assertIsDisplayed()
CcomposeTestRule.onNodeWithTag("screenA").assertIsDisplayed()
DcomposeTestRule.onNodeWithText("Screen A Content").assertIsDisplayed()
Attempts:
2 left
💡 Hint
After clicking the button, the UI should show ScreenB content.
🧠 Conceptual
expert
3:00remaining
What is the role of Semantics in Compose UI testing?
Why is setting semantics properties important for Compose UI testing?
AThey improve the app's performance by reducing recompositions.
BThey provide metadata that test code uses to find and interact with UI elements.
CThey automatically generate UI screenshots for tests.
DThey prevent UI elements from being displayed on the screen.
Attempts:
2 left
💡 Hint
Think about how tests identify UI elements beyond visible text.