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

AndroidComposeUiTestEnvironment

@ExperimentalTestApi
public abstract class AndroidComposeUiTestEnvironment<A extends ComponentActivity>


A test environment that can run tests using the test receiver scope. Note that some of the properties and methods on test will only work during the call to runTest, as they require that the environment has been set up.

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 constructors

Public methods

final @NonNull AndroidComposeUiTest<@NonNull A>

The receiver scope of the test passed to runTest.

final @NonNull R
<R extends Object> runTest(
    @ExtensionFunctionType @NonNull Function1<@NonNull AndroidComposeUiTest<@NonNull A>, @NonNull R> block
)

Runs the given block, setting up all test hooks before running the test and tearing them down after running the test.

Protected methods

abstract A

Returns the current host activity of type A.

Public constructors

AndroidComposeUiTestEnvironment

public <A extends ComponentActivity> AndroidComposeUiTestEnvironment(
    @NonNull CoroutineContext effectContext
)
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.

@NonNull CoroutineContext effectContext

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

Public methods

getTest

public final @NonNull AndroidComposeUiTest<@NonNull A> getTest()

The receiver scope of the test passed to runTest. Note that some of the properties and methods will only work during the call to runTest, as they require that the environment has been set up.

runTest

public final @NonNull R <R extends Object> runTest(
    @ExtensionFunctionType @NonNull Function1<@NonNull AndroidComposeUiTest<@NonNull A>, @NonNull R> block
)

Runs the given block, setting up all test hooks before running the test and tearing them down after running the test.

Protected methods

getActivity

protected abstract A getActivity()

Returns the current host activity of type A. 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.