title: Android Navigation Instrumentation test throws Method addObserver must be called on the main thread
body: <p>I have two Fragments, one being a home fragment in my graph. The User will be navigated to the second fragment upon clicking a button. It works as expected by navigating the user to the second fragment and displaying the text. So the graph is good.</p>
  <p>Now I wanted to write an instrumentation test.</p>
  <pre><code>@RunWith(AndroidJUnit4::class)
  class TransitionTest {
  
      @Test
      fun testNavigationToSecondFragment() {
          
          val navController = TestNavHostController(
              ApplicationProvider.getApplicationContext())
  
          navController.setGraph(R.navigation.my_graph) &lt;--throws exception
  
          // the rest of my test continues here
      }
  }
  </code></pre>
  <p>However, the line shown above to set the graph throws following exception:</p>
  <blockquote>
  <p>IllegalStateException: Method addObserver must be called on the main
  thread.</p>
  </blockquote>
  <p>My environment:</p>
  <blockquote>
  <p>fragment_version = 1.2.5 nav_version = 2.3.1 espresso = 3.3.0</p>
  </blockquote>
  <p>Does anyone have any idea what is going on and how to solve it?</p>