Odin

    Odin

    1 year ago
    Hi this might be a silly question, but is there something fancy you have to do to make testing in compose work? I have this test (see code in thread) but it looks like it just stalls and then after 45 sek it gives the error
    java.lang.AssertionError: Activity never becomes requested state "[RESUMED, CREATED, STARTED, DESTROYED]" (last lifecycle transition = "PRE_ON_CREATE")
    I saw that someone here had this problem before and solved it by adding a ComponentActivity in their manifest, but I just get the same result. Has anyone here had the same experience? 😄 🤔
    @LargeTest
    @HiltAndroidTest
    class TriviaMenuUiTest {
        @get:Rule(order = 0)
        val hiltAndroidRule = HiltAndroidRule(this)
    
        @get:Rule(order = 1)
        val composeTestRule = createComposeRule()
    
        @Test
        fun testQuickPlayButtonIsPresent() {
    
            composeTestRule.setContent {
                KiwiTheme {
                    TriviaMenu(
                        onQuickStart = { /*TODO*/ },
                        onBrowseCategories = { /*TODO*/ },
                        onBrowsePreviousResults = { /*TODO*/ },
                        signOut = { }
                    )
                }
            }
    
            composeTestRule.apply {
                onNodeWithTag("quick-play")
                    .assertExists("Quick play button does not exist")
    
                onNodeWithTag("quick-play")
                    .assertIsDisplayed()
            }
        }
    }
    theapache64

    theapache64

    6 months ago
    @Odin I think am having the same issue with gradle plugin
    7.2.0-beta01
    . Were you able to fix it?
    Odin

    Odin

    6 months ago
    I unfortunately can't recall what the solution to this was, but I think it was due to some dependency incompatibilities
    theapache64

    theapache64

    6 months ago
    @Odin No problem. In my case, the culprit was jacoco dependency