How do compose integration tests work under the ho...
# compose-android
v
How do compose integration tests work under the hood? Do they provide some support to control time on the main dispatcher like a TestScope? Or alternatively provide a way to change the default dispatcher of
rememberCoroutineScope()
? I'm looking to do something like this:
Copy code
@Composable fun Foo() { rememberCoroutineScope().launch { delay(1000) } }

@Test fun testSomething() { ...; composeRule.advanceTimeBy(1001); ...; }
Or would I need to inject a dispatcher and manually use that anywhere I would need to control time for tests?
z
Look at rule.mainClock
v
Oh wow, not sure how I missed that. Thanks, that's exactly what I was looking for and it's even mentioned in the docs. Maybe I was just too tired đŸ˜„
This constructor for AndroidComposeTestRule is meant for providing a custom test scheduler?
Copy code
@ExperimentalTestApi
    constructor(
        activityRule: R,
        effectContext: CoroutineContext = EmptyCoroutineContext,
        activityProvider: (R) -> A,
    ) : this(
        activityRule,
        AndroidComposeUiTestEnvironment(effectContext) { activityProvider(activityRule) },
    )
I'm looking to control the scheduler of other dispatchers (Default, IO) too by injecting those. I think there's no better way like for Main that is handled automatically?
z
You should be able to use it to provide a custom test scheduler, that’s what tests for internal Google apps do.
thank you frog 1