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

AndroidComposeUiTestEnvironment

A test environment that can [run tests]runTest using the [test receiver scope]test.

Source set: Android
public abstract class AndroidComposeUiTestEnvironment<A : ComponentActivity> internal constructor(
    private val config: ComposeUiTestConfig,
    private val enforceInputModeFromConfig: Boolean = false,
    private val useStandardTestDispatcherForComposition: Boolean,
)

A test environment that can run tests using the test receiver scope. Note that some of the properties and methods on test will only work during the call to runTest, as they require that the environment has been set up.

If the ComposeUiTestConfig.effectContext contains a TestDispatcher, that dispatcher will be used to run composition, and its TestCoroutineScheduler will be used to construct the MainTestClock. If the effectContext does not contain a TestDispatcher, a StandardTestDispatcher will be created for androidx.compose.ui.test.v2.* APIs; otherwise, an UnconfinedTestDispatcher will be created. In both cases, the TestCoroutineScheduler from the effectContext will be used if present.

Parameters

A The Activity type to be interacted with, which typically (but not necessarily) is the activity that was launched and 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.

Properties

test

Source set: Android
public val test: AndroidComposeUiTest<A> = testReceiverScope

The receiver scope of the test passed to runTest. Note that some of the properties and methods will only work during the call to runTest, as they require that the environment has been set up.

Functions

cancelAndRecreateRecomposer

Source set: Android
public fun cancelAndRecreateRecomposer()

Recreates the CoroutineContext associated with Compose being cancelled. This happens when an app moves from a regular ("Full screen") view of the app to a "Pop up" view AND certain properties in the manifest's android:configChanges are set to prevent a full tear down of the app. This is a somewhat rare case (see issuetracker.google.com/issues/309326720 for more details).

It does this by canceling the existing Recomposer and creates a new Recomposer (including a new recomposer coroutine scope for that new Recomposer) and a new ComposeIdlingResource.

To see full test: clickviewAddedAndRemovedWithRecomposerCancelledAndRecreatedclickStillWorks

runTestNonSuspendingLambda

Source set: Android
@Deprecated(
        level = DeprecationLevel.HIDDEN,
        message = "Replace with the same function, but with suspend block",
    )
    @JvmName("runTest") // for binary compatibility
    public fun <R> runTestNonSuspendingLambda(block: AndroidComposeUiTest<A>.() -> R?): R?

runTest

Source set: Android
public fun <R> runTest(block: suspend AndroidComposeUiTest<A>.() -> R): TestResult

Runs the given block, setting up all test hooks before running the test and tearing them down after running the test.