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
Zach Klippenstein (he/him) [MOD]
03/13/2024, 12:25 AM
Look at rule.mainClock
v
vide
03/13/2024, 1:54 PM
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 đŸ˜„
vide
03/13/2024, 2:00 PM
This constructor for AndroidComposeTestRule is meant for providing a custom test scheduler?
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
Zach Klippenstein (he/him) [MOD]
03/13/2024, 2:53 PM
You should be able to use it to provide a custom test scheduler, that’s what tests for internal Google apps do.