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

runEmptyComposeUiTest

Variant of runComposeUiTest that does not launch an Activity to host Compose content in and thus acts as an "empty shell".

runEmptyComposeUiTest

Source set: Android
@Deprecated(
    message =
        "Use `androidx.compose.ui.test.v2.runEmptyComposeUiTest` 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 runEmptyComposeUiTest(block: ComposeUiTest.() -> Unit): TestResult

Variant of runComposeUiTest that does not launch an Activity to host Compose content in and thus acts as an "empty shell". Use this if you need to have control over the timing and method of launching the Activity, for example when you want to launch it with a custom Intent, or if you have a complex test setup.

When using this method, calling ComposeUiTest.setContent will throw an IllegalStateException. Instead, you'll have to set the content in the Activity that you have launched yourself, either directly on the Activity or on an androidx.compose.ui.platform.AbstractComposeView. You will need to do this from within the test lambda, or the test framework will not be able to find the content.

Avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runEmptyComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.

runEmptyComposeUiTest

Source set: Android
public fun runEmptyComposeUiTest(block: ComposeUiTest.() -> Unit): TestResult

Variant of runComposeUiTest that does not launch an Activity to host Compose content in and thus acts as an "empty shell". Use this if you need to have control over the timing and method of launching the Activity, for example when you want to launch it with a custom Intent, or if you have a complex test setup.

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.

When using this method, calling ComposeUiTest.setContent will throw an IllegalStateException. Instead, you'll have to set the content in the Activity that you have launched yourself, either directly on the Activity or on an androidx.compose.ui.platform.AbstractComposeView. You will need to do this from within the test lambda, or the test framework will not be able to find the content.

Avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runEmptyComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.

Parameters

block The test function.

Content updated: