AndroidComposeUiTestEnvironment


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 : 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

android

Public functions

Unit
android
R
<R : Any?> runTest(block: AndroidComposeUiTest<A>.() -> R)

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

android

Public properties

AndroidComposeUiTest<A>

The receiver scope of the test passed to runTest.

android

Protected properties

abstract A?

Returns the current host activity of type A.

android

Public constructors

AndroidComposeUiTestEnvironment

<A : ComponentActivity> AndroidComposeUiTestEnvironment(
    effectContext: CoroutineContext = EmptyCoroutineContext
)
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.

effectContext: CoroutineContext = EmptyCoroutineContext

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

Public functions

cancelAndRecreateRecomposer

fun cancelAndRecreateRecomposer(): Unit

runTest

fun <R : Any?> runTest(block: AndroidComposeUiTest<A>.() -> R): R

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

Public properties

test

val testAndroidComposeUiTest<A>

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.

Protected properties

activity

protected abstract val activity: A?

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.