Member-only story
Android Compose UI Test
7 min readApr 15, 2025
Test your Android app’s UI to verify the app behavior. Use the testing cheat sheet quick reference of the most useful Compose test APIs. Read more details here. Check out the Android testing sample apps.
Setup
When you create a new Android project using Android Studio, the below dependencies are already added to the build.gradle
file.
// Test rules and transitive dependencies:
androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version")
// Needed for createComposeRule(), but not for createAndroidComposeRule<YourActivity>():
debugImplementation("androidx.compose.ui:ui-test-manifest:$compose_version")
- Create a new test class inside the package androidTest.
2. Example test code MainActivityTest:
- Adds `MainActivityTest` to verify the bottom navigation bar and tab switching between List and Calendar.
- Verifies that both List and Calendar tabs are displayed and selectable.
- Confirms that each tab displays the correct title when selected.
import androidx.compose.ui.test.assertIsDisplayed
import…