Deprecated Use androidx.compose.ui.test.v2.runAndroidComposeUiTest 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.
@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.
Avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runAndroidComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.
Parameters
| A | The Activity type to be launched, which typically (but not necessarily) hosts the Compose content |
| 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 test function. |
Deprecated Use androidx.compose.ui.test.v2.runAndroidComposeUiTest instead. The v2 APIs use StandardTestDispatcher instead of UnconfinedTestDispatcher, which aligns 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.
@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.
Avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runAndroidComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.
Parameters
| A | The Activity type to be launched, which typically (but not necessarily) hosts the Compose content |
| activityClass | The Class of the Activity type to be launched, corresponding to A. |
| 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 test function. |
@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.
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.
Avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runAndroidComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.
Parameters
| A | The Activity type to be launched, which typically (but not necessarily) hosts the Compose content |
| 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. |
@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.
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.
Avoid using androidx.compose.ui.test.junit4.ComposeTestRule (e.g., createComposeRule) inside runAndroidComposeUiTest or any of their respective variants. Since these APIs independently manage the test environment, mixing them may lead to unexpected behavior.
Parameters
| A | The Activity type to be launched, which typically (but not necessarily) hosts the Compose content |
| activityClass | The Class of the Activity type to be launched, corresponding to A. |
| 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. |