title: Espresso test Fail
body: <p>I am doing some Espresso testing in Android. The test is failing with this error:</p>
  <blockquote>
  <p>java.lang.ClassCastException:
  androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity
  cannot be cast to com.stavro_xhardha.pockettreasure.MainActivity</p>
  </blockquote>
  <p>This is my test method:</p>
  <pre class="lang-kotlin prettyprint-override"><code>@Test
  fun toolbarTitle_shouldContainCorrectInput() {
      val mockNavController = mock(NavController::class.java)
      val fragmentScenario = launchFragmentInContainer&lt;SetupFragment&gt;()
      fragmentScenario.onFragment {
          Navigation.setViewNavController(it.view!! , mockNavController)
      }
      onView(withId(R.id.toolbar)).check(matches(withText(&quot;Pick your country&quot;)))
  }
  </code></pre>
  <p>But the error doesn't come from the Test class but from my Fragment under test.
  The crash is executed in this line of code:</p>
  <pre><code>override fun onStart() {
      super.onStart()
      (activity!! as MainActivity).supportActionBar?.hide() //here
  }
  </code></pre>
  <p>What I don't get here is that I face no error when I run the app normally without test.</p>