{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

AndroidComposeUiTest

@ExperimentalTestApi
public sealed interface AndroidComposeUiTest<A extends ComponentActivity> extends ComposeUiTest


Variant of ComposeUiTest for when you want to have access to 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 extends 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 methods

abstract A

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

Inherited methods

From androidx.compose.ui.test.ComposeUiTest
abstract void
abstract @NonNull Density
abstract @NonNull MainTestClock
abstract void
abstract @NonNull T
<T extends Object> runOnIdle(@NonNull Function0<@NonNull T> action)
abstract @NonNull T
<T extends Object> runOnUiThread(@NonNull Function0<@NonNull T> action)
abstract void
setContent(@Composable @NonNull Function0<Unit> composable)
abstract void
abstract void
abstract void
waitUntil(
    long timeoutMillis,
    @NonNull Function0<@NonNull Boolean> condition
)
From androidx.compose.ui.test.SemanticsNodeInteractionsProvider
abstract @NonNull SemanticsNodeInteractionCollection
onAllNodes(@NonNull SemanticsMatcher matcher, boolean useUnmergedTree)

Finds all semantics nodes that match the given condition.

abstract @NonNull SemanticsNodeInteraction
onNode(@NonNull SemanticsMatcher matcher, boolean useUnmergedTree)

Finds a semantics node that matches the given condition.

Public methods

getActivity

abstract A getActivity()

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.