androidx.compose.ui.test.junit4

Interfaces

ComposeContentTestRule

A ComposeTestRule that allows you to set content without the necessity to provide a host for the content.

android
ComposeTestRule

A TestRule that allows you to test and control composables and applications using Compose.

android

Classes

AndroidComposeTestRule
android
AndroidComposeTestRule.AndroidComposeStatement

This class is deprecated. Do not instantiate this Statement, use AndroidComposeTestRule instead

android
DesktopComposeTestRule
android
GoldenConfig
android
ScreenshotResultProto
android
ScreenshotTestRule
android
SkiaTestAlbum
android
SkiaTestAlbum.Report
android
StateRestorationTester

Helps to test the state restoration for your Composable component.

android

Enums

Top-level functions summary

ScreenshotTestRule
@InternalTestApi
DesktopScreenshotTestRule(
    modulePath: String,
    fsGoldenPath: String,
    repoGoldenPath: String
)
android
inline AndroidComposeTestRule<ActivityScenarioRule<A>, A>

Factory method to provide android specific implementation of createComposeRule, for a given activity class type A.

android
AndroidComposeTestRule<ActivityScenarioRule<A>, A>

Factory method to provide android specific implementation of createComposeRule, for a given activityClass.

android
inline AndroidComposeTestRule<ActivityScenarioRule<A>, A>

Factory method to provide android specific implementation of createComposeRule, for a given activity class type A.

android
AndroidComposeTestRule<ActivityScenarioRule<A>, A>
@ExperimentalTestApi
<A : ComponentActivity> createAndroidComposeRule(
    activityClass: Class<A>,
    effectContext: CoroutineContext
)

Factory method to provide android specific implementation of createComposeRule, for a given activityClass.

android
ComposeContentTestRule

Factory method to provide an implementation of ComposeContentTestRule.

android
ComposeContentTestRule

Factory method to provide an implementation of ComposeContentTestRule.

android
ComposeTestRule

Factory method to provide an implementation of ComposeTestRule that doesn't create a compose host for you in which you can set content.

android
ComposeTestRule

Factory method to provide an implementation of ComposeTestRule that doesn't create a compose host for you in which you can set content.

android

Top-level functions

DesktopScreenshotTestRule

@InternalTestApi
fun DesktopScreenshotTestRule(
    modulePath: String,
    fsGoldenPath: String = System.getProperty("GOLDEN_PATH"),
    repoGoldenPath: String = "platform/frameworks/support-golden"
): ScreenshotTestRule

createAndroidComposeRule

inline fun <A : ComponentActivity> createAndroidComposeRule(): AndroidComposeTestRule<ActivityScenarioRule<A>, A>

Factory method to provide android specific implementation of createComposeRule, for a given activity class type A.

This method is useful for tests that require a custom Activity. This is usually the case for tests where the compose content is set by that Activity, instead of via the test rule's setContent. Make sure that you add the provided activity into your app's manifest file (usually in main/AndroidManifest.xml).

This creates a test rule that is using ActivityScenarioRule as the activity launcher. If you would like to use a different one you can create AndroidComposeTestRule directly and supply it with your own launcher.

If your test doesn't require a specific Activity, use createComposeRule instead.

createAndroidComposeRule

fun <A : ComponentActivity> createAndroidComposeRule(activityClass: Class<A>): AndroidComposeTestRule<ActivityScenarioRule<A>, A>

Factory method to provide android specific implementation of createComposeRule, for a given activityClass.

This method is useful for tests that require a custom Activity. This is usually the case for tests where the compose content is set by that Activity, instead of via the test rule's setContent. Make sure that you add the provided activity into your app's manifest file (usually in main/AndroidManifest.xml).

This creates a test rule that is using ActivityScenarioRule as the activity launcher. If you would like to use a different one you can create AndroidComposeTestRule directly and supply it with your own launcher.

If your test doesn't require a specific Activity, use createComposeRule instead.

createAndroidComposeRule

@ExperimentalTestApi
inline fun <A : ComponentActivity> createAndroidComposeRule(
    effectContext: CoroutineContext = EmptyCoroutineContext
): AndroidComposeTestRule<ActivityScenarioRule<A>, A>

Factory method to provide android specific implementation of createComposeRule, for a given activity class type A.

This method is useful for tests that require a custom Activity. This is usually the case for tests where the compose content is set by that Activity, instead of via the test rule's setContent. Make sure that you add the provided activity into your app's manifest file (usually in main/AndroidManifest.xml).

This creates a test rule that is using ActivityScenarioRule as the activity launcher. If you would like to use a different one you can create AndroidComposeTestRule directly and supply it with your own launcher.

If your test doesn't require a specific Activity, use createComposeRule instead.

createAndroidComposeRule

@ExperimentalTestApi
fun <A : ComponentActivity> createAndroidComposeRule(
    activityClass: Class<A>,
    effectContext: CoroutineContext = EmptyCoroutineContext
): AndroidComposeTestRule<ActivityScenarioRule<A>, A>

Factory method to provide android specific implementation of createComposeRule, for a given activityClass.

This method is useful for tests that require a custom Activity. This is usually the case for tests where the compose content is set by that Activity, instead of via the test rule's setContent. Make sure that you add the provided activity into your app's manifest file (usually in main/AndroidManifest.xml).

This creates a test rule that is using ActivityScenarioRule as the activity launcher. If you would like to use a different one you can create AndroidComposeTestRule directly and supply it with your own launcher.

If your test doesn't require a specific Activity, use createComposeRule instead.

createComposeRule

fun createComposeRule(): ComposeContentTestRule

Factory method to provide an implementation of ComposeContentTestRule.

This method is useful for tests in compose libraries where it is irrelevant where the compose content is hosted (e.g. an Activity on Android). Such tests typically set compose content themselves via setContent and only instrument and assert that content.

For Android this will use the default Activity (android.app.Activity). You need to add a reference to this activity into the manifest file of the corresponding tests (usually in androidTest/AndroidManifest.xml). If your Android test requires a specific Activity to be launched, see createAndroidComposeRule.

createComposeRule

@ExperimentalTestApi
fun createComposeRule(effectContext: CoroutineContext = EmptyCoroutineContext): ComposeContentTestRule

Factory method to provide an implementation of ComposeContentTestRule.

This method is useful for tests in compose libraries where it is irrelevant where the compose content is hosted (e.g. an Activity on Android). Such tests typically set compose content themselves via setContent and only instrument and assert that content.

For Android this will use the default Activity (android.app.Activity). You need to add a reference to this activity into the manifest file of the corresponding tests (usually in androidTest/AndroidManifest.xml). If your Android test requires a specific Activity to be launched, see createAndroidComposeRule.

Parameters
effectContext: CoroutineContext = EmptyCoroutineContext

The CoroutineContext used to run the composition. The context for LaunchedEffects and rememberCoroutineScope will be derived from this context.

createEmptyComposeRule

fun createEmptyComposeRule(): ComposeTestRule

Factory method to provide an implementation of ComposeTestRule that doesn't create a compose host for you in which you can set content.

This method is useful for tests that need to create their own compose host during the test. The returned test rule will not create a host, and consequently does not provide a setContent method. To set content in tests using this rule, use the appropriate setContent methods from your compose host.

A typical use case on Android is when the test needs to launch an Activity (the compose host) after one or more dependencies have been injected.

createEmptyComposeRule

@ExperimentalTestApi
fun createEmptyComposeRule(
    effectContext: CoroutineContext = EmptyCoroutineContext
): ComposeTestRule

Factory method to provide an implementation of ComposeTestRule that doesn't create a compose host for you in which you can set content.

This method is useful for tests that need to create their own compose host during the test. The returned test rule will not create a host, and consequently does not provide a setContent method. To set content in tests using this rule, use the appropriate setContent methods from your compose host.

A typical use case on Android is when the test needs to launch an Activity (the compose host) after one or more dependencies have been injected.

Parameters
effectContext: CoroutineContext = EmptyCoroutineContext

The CoroutineContext used to run the composition. The context for LaunchedEffects and rememberCoroutineScope will be derived from this context.