runAndroidComposeUiTest
@Deprecated(
message =
"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.",
level = DeprecationLevel.WARNING,
)
public 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. |
runAndroidComposeUiTest
@Deprecated(
message =
"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.",
level = DeprecationLevel.WARNING,
)
public 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. |
runAndroidComposeUiTest
@Deprecated(
level = DeprecationLevel.WARNING,
message =
"Use runAndroidComposeUiTest(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" +
"runAndroidComposeUiTest<Activity>(effectContext, runTestContext, testTimeout) { ... }\n" +
"After:\n" +
"runAndroidComposeUiTest<Activity>(ComposeUiTestConfig(effectContext, runTestContext, testTimeout)) { ... }",
replaceWith =
ReplaceWith(
"runAndroidComposeUiTest<A>(ComposeUiTestConfig(effectContext, runTestContext, testTimeout), block)"
),
)
public inline fun <reified A : ComponentActivity> runAndroidComposeUiTest(
effectContext: CoroutineContext = kotlin.coroutines.EmptyCoroutineContext,
runTestContext: CoroutineContext = kotlin.coroutines.EmptyCoroutineContext,
testTimeout: Duration = kotlin.time.Duration.parse("60s"),
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. |
runAndroidComposeUiTest
public inline fun <reified A : ComponentActivity> runAndroidComposeUiTest(
config: ComposeUiTestConfig,
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. |
| 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. |
runAndroidComposeUiTest
public inline fun <reified A : ComponentActivity> runAndroidComposeUiTest(
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.
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
| A | The Activity type to be launched, which typically (but not necessarily) hosts the Compose content. |
| block | The test function. |
runAndroidComposeUiTest
@Deprecated(
level = DeprecationLevel.WARNING,
message =
"Use runAndroidComposeUiTest(activityClass, 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" +
"runAndroidComposeUiTest(activityClass, effectContext, runTestContext, testTimeout) { ... }\n" +
"After:\n" +
"runAndroidComposeUiTest(activityClass, ComposeUiTestConfig(effectContext, runTestContext, testTimeout)) { ... }",
)
public 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. |
runAndroidComposeUiTest
public fun <A : ComponentActivity> runAndroidComposeUiTest(
activityClass: Class<A>,
config: ComposeUiTestConfig,
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. |
| 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. |
runAndroidComposeUiTest
public fun <A : ComponentActivity> runAndroidComposeUiTest(
activityClass: Class<A>,
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.
The default ComposeUiTestConfig sets the InputMode to Touch for each test. To configure the test
- to run with a different input mode (such as
- or customize other environment settings, use the overload that accepts a ComposeUiTestConfig.
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. |
| block | The test function. |