Hi all :android-wave: , I am getting the following error when running Compose UI tests. Could anyone...
a
Hi all 👋 , I am getting the following error when running Compose UI tests. Could anyone please help thank you color . Error
Copy code
java.lang.IllegalStateException: State must be at least 'CREATED' to be moved to 'DESTROYED' in component NavBackStackEntry(7a23a02c-5dfa-43df-8510-97bda229a7da) destination=Destination(0x98d0beb0) route=settings
Dependencies
Copy code
navigation-compose = "2.9.0-beta03"
plus one 2
Test code
Copy code
@RunWith(AndroidJUnit4::class)
internal class NavigationTest {
    @get:Rule(order = 0)
    val koinTestRule = KoinTestRule(
        modules = listOf(
            MyAppModule().module,
        ),
    )

    @get:Rule(order = 1)
    val composeTestRule = createAndroidComposeRule<MainActivity>()

    @Test
    fun navigationTest() {
        composeTestRule
            .onNodeWithTag(
                testTag = "screen_home",
            )
            .assertIsDisplayed()
        composeTestRule.waitUntil {
            composeTestRule
                .onNodeWithContentDescription(
                    "Settings",
                )
                .isDisplayed()
        }
 
        // This click action is throwing the exception. It navigates to Settings screen on clicking.
        composeTestRule
            .onNodeWithContentDescription(
                "Settings",
            )
            .performClick()
        composeTestRule.waitForIdle()
    }
}
g
Hi @Abhimanyu, have you found solution for this problem?
a
Hi @Gulshan Patidar, I have reported the issue here • https://youtrack.jetbrains.com/issue/CMP-8731 They asked me to report it on the Google Issue Tracker since this library is maintained by Google. • https://issuetracker.google.com/issues/460847526 Please upvote and add more details in the Issue Tracker if you are experiencing the same issue.
g
Got it. Thank you
Hi @Abhimanyu. this can be fixed if we use createComposeRule(StandardTestDispatcher()) instead of createAndroidComposeRuleMainActivity() Also make sure to launch the MainActivity using ActivityScenerio in the @ Before block of the test.
a
I tried this approach, and it works when running a single test. However, I’m getting the following error when I run multiple tests in the same file.
Copy code
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
g
Can you please send the full error?