AndroidComposeUiTestEnvironment
@ExperimentalTestApi
inline fun <A : ComponentActivity> AndroidComposeUiTestEnvironment(
effectContext: CoroutineContext = EmptyCoroutineContext,
runTestContext: CoroutineContext = EmptyCoroutineContext,
testTimeout: Duration = 60.seconds,
crossinline activityProvider: () -> A?,
): AndroidComposeUiTestEnvironment<A>
Creates an AndroidComposeUiTestEnvironment that retrieves the
host Activity by delegating to the given activityProvider. Use
this if you need to launch an Activity in a way that is not compatible with any of the existing
runComposeUiTest, runAndroidComposeUiTest, or runEmptyComposeUiTest methods.
Valid use cases include, but are not limited to, creating your own JUnit test rule that
implements AndroidComposeUiTest by delegating to AndroidComposeUiTestEnvironment.test. See
AndroidComposeTestRule for a reference
implementation.
The activityProvider is called every time activity is called,
which in turn is called when setContent is called.
The most common implementation of an activityProvider retrieves the activity from a backing
ActivityScenario (that the caller launches within the lambda passed to runTest), but one is
not limited to this pattern.
Parameters
| activityProvider | A lambda that should return the current Activity instance of type A, if it is available. If it is not available, it should return null. |
| A | The Activity type to be interacted with, which typically (but not necessarily) is the activity that was launched and 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. By default it 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. |
