[ Web Proxy ]
URL:
Viewing: https://developer.android.com/develop/ui/compose/testing [Back]  [Original]

Test your Compose layout  |  Jetpack Compose  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]

Test your Compose layout Stay organized with collections Save and categorize content based on your preferences.

Android testing setup

Use an Android skill to analyze and set up test infrastructure, test harnesses, unit tests, and UI tests for native Android apps.
To install the skill from the Android CLI, run:
android skills add --skill testing-setup

Test your app's UI to verify that behavior of your Compose code is correct. This lets you catch errors early and improve the quality of your app.

Compose provides a set of testing APIs to find elements, verify their attributes, and perform user actions. The APIs also include advanced features such as time manipulation. Use these APIs to create robust tests that verify your app's behavior.

Important: For more on testing Android apps in general, including testing View elements, see the general testing section. A good place to start is the Fundamentals of testing Android apps guide.

Views

If you are working with views instead of Compose, see the general Test apps on Android section.

In particular, a good place to start is the Automate UI tests guide. It lays out how you can automate tests that run on-device, including when using views.

Key Concepts

The following are some key concepts for testing your Compose code:

Testing cheatsheet

See the testing cheatsheet for an overview of all the key topics you should learn about testing in Compose.

Setup

Set up your app to let you test Compose code.

First, add the following dependencies to the build.gradle file of the module containing your UI tests:

// 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")

This module includes a ComposeTestRule and an implementation for Android called AndroidComposeTestRule. Through this rule you can set Compose content or access the activity. You construct the rules using factory functions, either createComposeRule or, if you need access to an activity, createAndroidComposeRule. A typical UI test for Compose looks like this:

// file: app/src/androidTest/java/com/package/MyComposeTest.kt

class MyComposeTest {

    @get:Rule val composeTestRule = createComposeRule()
    // use createAndroidComposeRule<YourActivity>() if you need access to
    // an activity

    @Test
    fun myTest() {
        // Start the app
        composeTestRule.setContent {
            MyAppTheme {
                MainScreen(uiState = fakeUiState, /*...*/)
            }
        }

        composeTestRule.onNodeWithText("Continue").performClick()

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

Additional Resources

Codelab

To learn more, try the Jetpack Compose Testing codelab.

Samples

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-08-14 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-14 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page