runComposeUiTest

Function

Common
@ExperimentalTestApi
expect fun runComposeUiTest(
    effectContext: CoroutineContext = EmptyCoroutineContext,
    runTestContext: CoroutineContext = EmptyCoroutineContext,
    testTimeout: Duration = 60.seconds,
    block: suspend ComposeUiTest.() -> Unit,
): TestResult

Sets up the test environment, runs the given test and then tears down the test environment. Use the methods on ComposeUiTest in the test to find Compose content and make assertions on it. If you need access to platform specific elements (such as the Activity on Android), use one of the platform specific variants of this method, e.g. runAndroidComposeUiTest on Android.

Implementations of this method will launch a Compose host (such as an Activity on Android) for you. If your test needs to launch its own host, use a platform specific variant that doesn't launch anything for you (if available), e.g. runEmptyComposeUiTest on Android. Always make sure that the Compose content is set during execution of the test lambda so the test framework is aware of the content. Whether you need to launch the host from within the test lambda as well depends on the platform.

Keeping a reference to the ComposeUiTest outside of this function is an error.

Parameters

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
actual fun runComposeUiTest(
    effectContext: CoroutineContext,
    runTestContext: CoroutineContext,
    testTimeout: Duration,
    block: suspend ComposeUiTest.() -> Unit,
): TestResult

Parameters

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 suspendable test body.