🌈 Create new beautiful Compose Gradients with our new wesite ->
Function

runComposeUiTest

Sets up the test environment, runs the given [test]block and then tears down the test environment.

runComposeUiTest

Source set: Android
@Deprecated(
    message =
        "Use `androidx.compose.ui.test.v2.runComposeUiTest` instead. The v2 APIs align with " +
            "standard coroutine behavior by queuing tasks rather than executing them " +
            "immediately. Tests relying on immediate execution may require explicit " +
            "synchronization. Please refer to the migration guide for more details.",
    level = DeprecationLevel.WARNING,
)
public fun runComposeUiTest(
    effectContext: CoroutineContext,
    runTestContext: CoroutineContext,
    testTimeout: Duration,
    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. Also avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.

Parameters

effectContext The 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.
runTestContext The 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.
testTimeout The Duration within which the test is expected to complete, otherwise a platform specific timeout exception will be thrown.
block The suspendable test body.

runComposeUiTest

Source set: Android
@Deprecated(
    level = DeprecationLevel.WARNING,
    message =
        "Use runComposeUiTest(config: ComposeUiTestConfig, block) instead. " +
            "The individual parameters `effectContext`, `runTestContext`, and `testTimeout` " +
            "have been consolidated into [ComposeUiTestConfig] to allow for more flexible test " +
            "environment configuration.\n" +
            "Before:\n" +
            "runComposeUiTest(effectContext, runTestContext, testTimeout) { ... }\n" +
            "After:\n" +
            "runComposeUiTest(ComposeUiTestConfig(effectContext, runTestContext, testTimeout)) { ... }",
    replaceWith =
        ReplaceWith(
            "runComposeUiTest(ComposeUiTestConfig(effectContext, runTestContext, testTimeout), block)"
        ),
)
public fun runComposeUiTest(
    effectContext: CoroutineContext,
    runTestContext: CoroutineContext,
    testTimeout: Duration,
    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.

This implementation uses kotlinx.coroutines.test.StandardTestDispatcher by default for running composition. This ensures that the test behavior is consistent with kotlinx.coroutines.test.runTest and provides explicit control over coroutine execution order. This means you may need to explicitly advance time or run current coroutines when testing complex coroutine logic, as tasks are queued on the scheduler rather than running eagerly.

Keeping a reference to the ComposeUiTest outside of this function is an error. Also avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.

Parameters

effectContext The CoroutineContext used to run the composition. The context for LaunchedEffects and rememberCoroutineScope will be derived from this context. If this context contains a TestDispatcher, it is used for composition and the MainTestClock. Otherwise, a kotlinx.coroutines.test.StandardTestDispatcher is created and used. This new dispatcher will share the TestCoroutineScheduler from effectContext if one is present.
runTestContext The 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.
testTimeout The Duration within which the test is expected to complete, otherwise a platform specific timeout exception will be thrown.
block The suspendable test body.

runComposeUiTest

Source set: Android
public fun runComposeUiTest(
    config: ComposeUiTestConfig,
    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. Also avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.

Parameters

config The ComposeUiTestConfig used to set up the test environment, providing control over the CoroutineContext used for composition, the test timeout, and other environment-specific settings.
block The suspendable test body.

runComposeUiTest

Source set: Android
public fun runComposeUiTest(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. Also avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.

The default ComposeUiTestConfig sets the InputMode to Touch for each test. To configure the test to run with a different input mode (such as Keyboard) or customize other environment settings, use the overload that accepts a ComposeUiTestConfig.

Parameters

block The suspendable test body.

runComposeUiTest

Source set: Common
@Deprecated(
    message =
        "Use `androidx.compose.ui.test.v2.runComposeUiTest` instead. The v2 APIs align with " +
            "standard coroutine behavior by queuing tasks rather than executing them " +
            "immediately. Tests relying on immediate execution may require explicit " +
            "synchronization. Please refer to the migration guide for more details.",
    level = DeprecationLevel.WARNING,
)
public 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.

This function follows the semantics of kotlinx.coroutines.test.runTest. On JVM and Native it behaves similarly to runBlocking. On web targets it returns a TestResult backed by a Promise.

For multiplatform tests, make the test return TestResult and immediately return the result of runComposeUiTest. Keep assertions inside the block, and do not execute code after this call.

Example:

Keeping a reference to the [ComposeUiTest](/jetpack-compose/androidx.compose.ui/ui-test/interfaces/ComposeUiTest/api) outside of this function is an error.

See also:
* [kotlinx.coroutines.test.runTest](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/run-test.html)
* [TestResult](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-result/)

#### Parameters

| | |
| --- | --- |
| effectContext | The [CoroutineContext] used to run the composition. The context for `LaunchedEffect`s 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]. |
| runTestContext | The [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]. |
| testTimeout | The [Duration] within which the test is expected to complete, otherwise a platform specific timeout exception will be thrown. |
| block | The test function. |

<h3 id="runcomposeuitest-effectcontext-runtestcontext-testtimeout-block-4">runComposeUiTest</h3>

> Source set: Common

@Deprecated( level = DeprecationLevel.WARNING, message = "Use runComposeUiTest(config, block) instead. " + "The individual parameters effectContext, runTestContext, and testTimeout " + "have been consolidated into ComposeUiTestConfig to allow for more flexible test " + "environment configuration.\n" + "Before:\n" + "runComposeUiTest(effectContext, runTestContext, testTimeout) { ... }\n" + "After:\n" + "runComposeUiTest(ComposeUiTestConfig(effectContext, runTestContext, testTimeout)) { ... }", replaceWith = ReplaceWith( "runComposeUiTest(ComposeUiTestConfig(effectContext, runTestContext, testTimeout), block)" ), ) public fun runComposeUiTest( effectContext: CoroutineContext = kotlin.coroutines.EmptyCoroutineContext, runTestContext: CoroutineContext = kotlin.coroutines.EmptyCoroutineContext, testTimeout: Duration = kotlin.time.Duration.parse("60s"), 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](/jetpack-compose/androidx.compose.ui/ui-test/interfaces/ComposeUiTest/api) 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.

This implementation uses `kotlinx.coroutines.test.StandardTestDispatcher` by default for running
composition. This ensures that the test behavior is consistent with
`kotlinx.coroutines.test.runTest` and provides explicit control over coroutine execution order.
This means you may need to explicitly advance time or run current coroutines when testing complex
coroutine logic, as tasks are queued on the scheduler rather than running eagerly.

This function follows the semantics of `kotlinx.coroutines.test.runTest`. On JVM and Native it
behaves similarly to `runBlocking`. On web targets it returns a `TestResult` backed by a
`Promise`.

For multiplatform tests, make the test return `TestResult` and immediately return the result of
[runComposeUiTest](/jetpack-compose/androidx.compose.ui/ui-test/functions/runComposeUiTest/api). Keep assertions inside the `block`, and do not execute code after this call.

Example:

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

See also:

Parameters

effectContext The CoroutineContext used to run the composition. The context for LaunchedEffects and rememberCoroutineScope will be derived from this context. If this context contains a TestDispatcher, it is used for composition and the MainTestClock. Otherwise, a kotlinx.coroutines.test.StandardTestDispatcher is created and used. This new dispatcher will share the TestCoroutineScheduler from effectContext if one is present.
runTestContext The 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.
testTimeout The Duration within which the test is expected to complete, otherwise a platform specific timeout exception will be thrown.
block The test function.

runComposeUiTest

Source set: Common
public fun runComposeUiTest(
    config: ComposeUiTestConfig,
    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

config The ComposeUiTestConfig used to set up the test environment, providing control over the CoroutineContext used for composition, the test timeout, and other environment-specific settings.
block The test function.

runComposeUiTest

Source set: Common
public fun runComposeUiTest(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.

The default ComposeUiTestConfig sets the InputMode to Touch for each test. To configure the test

    Keyboard)

  • to run with a different input mode (such as
  • or customize other environment settings, use the overload that accepts a ComposeUiTestConfig.

Parameters

block The test function.