AndroidComposeUiTest


Variant of ComposeUiTest for when you want to have access the current activity of type A. The activity might not always be available, for example if the test navigates to another activity. In such cases, activity will return null.

An instance of AndroidComposeUiTest can be obtained by calling runAndroidComposeUiTest, the argument to which will have it as the receiver scope.

Note that any Compose content can be found and tested, regardless if it is hosted by activity or not. What is important, is that the content is set during the lambda passed to runAndroidComposeUiTest (not before, and not after), and that the activity that is actually hosting the Compose content is in resumed state.

Parameters
<A : ComponentActivity>

The Activity type to be interacted with, which typically (but not necessarily) is the activity that was launched and hosts the Compose content

Summary

Public properties

A?

Returns the current activity of type A used in this ComposeUiTest.

android

Inherited functions

From androidx.compose.ui.test.ComposeUiTest
suspend Unit

Suspends until the UI is idle.

android
Unit

Registers an IdlingResource in this test.

android
T
<T : Any?> runOnIdle(action: () -> T)

Executes the given action in the same way as runOnUiThread but waits until the app is idle before executing the action.

android
T
<T : Any?> runOnUiThread(action: () -> T)

Runs the given action on the UI thread.

android
Unit
setContent(composable: @Composable () -> Unit)

Sets the given composable as the content to be tested.

android
Unit

Unregisters an IdlingResource from this test.

android
Unit

Waits for the UI to become idle.

android
Unit
waitUntil(
    conditionDescription: String?,
    timeoutMillis: Long,
    condition: () -> Boolean
)

Blocks until the given condition is satisfied.

android
From androidx.compose.ui.test.SemanticsNodeInteractionsProvider
SemanticsNodeInteractionCollection
onAllNodes(matcher: SemanticsMatcher, useUnmergedTree: Boolean)

Finds all semantics nodes that match the given condition.

android
SemanticsNodeInteraction
onNode(matcher: SemanticsMatcher, useUnmergedTree: Boolean)

Finds a semantics node that matches the given condition.

android

Inherited properties

From androidx.compose.ui.test.ComposeUiTest
Density

Current device screen's density.

android
MainTestClock

Clock that drives frames and recompositions in compose tests.

android

Public properties

activity

val activity: A?

Returns the current activity of type A used in this ComposeUiTest. If no such activity is available, for example if you've navigated to a different activity and the original host has now been destroyed, this will return null.

Note that you should never hold on to a reference to the Activity, always use activity to interact with the Activity.