title: How to test if a fragment is visible with Espresso
body: <p>I wrote a very simple <code>Activity</code> with a Button. When the button is clicked, I will start a new <code>Fragment</code>. Now I want to test this logic in my Espresso UI Test. So I wrote this UI Test for my <code>Activity</code></p>
  
  <pre><code>@RunWith(AndroidJUnit4::class)
  @LargeTest
  class MainMenuUiTest {
  
  @get: Rule
  val activityTestRule: ActivityTestRule&lt;MainActivity&gt; = ActivityTestRule(MainActivity::class.java)
  
   @Test
   fun switchToFragment() {
       onView(withId(R.id.btn)).perform()
   }
  </code></pre>
  
  <p>}</p>
  
  <p>How can I test that my <code>Fragment</code> is displayed when the button is clicked? </p>