runAndroidComposeUiTest

Function

Android
@ExperimentalTestApi
inline fun <reified A : ComponentActivity> runAndroidComposeUiTest(
    effectContext: CoroutineContext = EmptyCoroutineContext,
    runTestContext: CoroutineContext = EmptyCoroutineContext,
    testTimeout: Duration = 60.seconds,
    noinline block: suspend AndroidComposeUiTest<A>.() -> Unit,
): TestResult

Variant of runComposeUiTest that allows you to specify which Activity should be launched. Be aware that if the Activity sets content during its launch, you cannot use setContent on the ComposeUiTest anymore as this would override the content and can lead to subtle bugs.

Parameters

AThe Activity type to be launched, which typically (but not necessarily) hosts the Compose content
effectContextThe CoroutineContext used to run the composition. The context for LaunchedEffects and rememberCoroutineScope will be derived from this context. If this context contains a TestDispatcher or TestCoroutineScheduler (in that order), it will be used for composition and the MainTestClock.
runTestContextThe CoroutineContext used to create the context to run the test block. By default block will run using kotlinx.coroutines.test.StandardTestDispatcher. runTestContext and effectContext must not share TestCoroutineScheduler.
testTimeoutThe Duration within which the test is expected to complete, otherwise a platform specific timeout exception will be thrown.
blockThe test function.
Android
@ExperimentalTestApi
fun <A : ComponentActivity> runAndroidComposeUiTest(
    activityClass: Class<A>,
    effectContext: CoroutineContext = EmptyCoroutineContext,
    runTestContext: CoroutineContext = EmptyCoroutineContext,
    testTimeout: Duration = 60.seconds,
    block: suspend AndroidComposeUiTest<A>.() -> Unit,
): TestResult

Variant of runComposeUiTest that allows you to specify which Activity should be launched. Be aware that if the Activity sets content during its launch, you cannot use setContent on the ComposeUiTest anymore as this would override the content and can lead to subtle bugs.

Parameters

AThe Activity type to be launched, which typically (but not necessarily) hosts the Compose content
activityClassThe Class of the Activity type to be launched, corresponding to A.
effectContextThe CoroutineContext used to run the composition. The context for LaunchedEffects and rememberCoroutineScope will be derived from this context. If this context contains a TestDispatcher or TestCoroutineScheduler (in that order), it will be used for composition and the MainTestClock.
runTestContextThe CoroutineContext used to create the context to run the test block. By default block will run using kotlinx.coroutines.test.StandardTestDispatcher. runTestContext and effectContext must not share TestCoroutineScheduler.
testTimeoutThe Duration within which the test is expected to complete, otherwise a platform specific timeout exception will be thrown.
blockThe test function.