1

java.lang.IllegalStateException: Method addObserver must be called on the main thread.

@Test fun verifyAllRequiredViewsAreDisplayed() {

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)

}

Qumber Abbas
  • 560
  • 1
  • 4
  • 11
  • Any solution, I have the same problem? – ysfcyln Apr 01 '21 at 11:00
  • Can this one help? https://stackoverflow.com/questions/64686001/android-navigation-instrumentation-test-throws-method-addobserver-must-be-called The `LifecycleRegistry` verify the method on main thread since 2.3.0 https://developer.android.com/jetpack/androidx/releases/lifecycle#2.3.0 – Long Ranger Apr 18 '21 at 02:39

0 Answers0