Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Facing Exception UI Testing || Android Navigation Testing #107

Open
QumberAbbas12 opened this issue Mar 11, 2021 · 0 comments
Open

Facing Exception UI Testing || Android Navigation Testing #107

QumberAbbas12 opened this issue Mar 11, 2021 · 0 comments

Comments

@QumberAbbas12
Copy link

QumberAbbas12 commented Mar 11, 2021

java.lang.IllegalStateException: Method addObserver must be called on the main thread.
Line navController.setGraph(R.navigation.navigation_onboarding)

`@RunWith(AndroidJUnit4::class)
class UserEmailFragmentTest {

@get:Rule
val activityRule = activityScenarioRule<OnboardingActivity>()

@Test
fun verifyAllRequiredViewsAreDisplayed() {

    // Create a TestNavHostController
    val navController = TestNavHostController(
        ApplicationProvider.getApplicationContext()
    )

    navController.setGraph(R.navigation.navigation_onboarding)

    // Create a graphical FragmentScenario for the TitleScreen
    val userEmailScenario = launchFragmentInContainer<EmailFragment>()

    // Set the NavController property on the fragment
    userEmailScenario.onFragment { fragment ->
        Navigation.setViewNavController(fragment.requireView(), navController)
    }

    assertThat(navController.currentDestination?.id).isEqualTo(R.id.emailFragment)
}

}`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant