Sitemap

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.

https://developer.android.com/static/develop/ui/compose/images/compose-testing-cheatsheet.png

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")
  1. 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…

--

--

Andres Sandoval
Andres Sandoval

Written by Andres Sandoval

I'm a passionate Android Software Engineer with over 11 years of experience. andresand.github.io/andres-about-me/ buymeacoffee.com/andresand

No responses yet