anyone know how to use ComposeTestRule so that it ...
# compose
m
anyone know how to use ComposeTestRule so that it doesn’t auto launch the activity? With ActivityScenario i can just delay creating it until i’m ready for that (and with ActivityTestRule, which i think is deprecated) you could tell it not to auto launch. The problem with auto launch is that if you have processes (like a data load) that kick off on onStart or something like that, you can’t effectively stub out the calls without creating a test class for each unique set of responses from that data load.
This is sort of the best I’ve been able to do but it’s a bit ugly:
Copy code
inline fun <reified A: ComponentActivity> launchComposeTest(
        crossinline block:  AndroidComposeTestRule<ActivityScenarioRule<A>, A>.() -> Unit
    ) {
        val rule = createAndroidComposeRule<A>()
        rule.apply(
            object: Statement() {
                override fun evaluate() {
                    rule.block()
                }
            },
            Description.EMPTY
        ).evaluate()
    }

    @Test
    fun startMainActivity() {
        launchComposeTest<MainActivity> {
            onRoot()
                .assertIsDisplayed()
        }
    }