title: Android Espresso : correctly test closing app with pressBack
body: <p>I'm trying to implement some navigation tests with espresso. Actually i want to check if the application has been closed by the use of the Back key on the main screen, just after a fresh start.
  Here is a piece of code i'm using.</p>
  
  <pre><code>class NavigationTests  {
      @get:Rule
      val mActivityTestRule: ActivityTestRule&lt;MainActivity&gt; = ActivityTestRule(MainActivity::class.java)
  
      @Test
      fun backOnEmptyHomeMustExit(){
          Espresso.pressBack()
          Assert.assertTrue(mActivityTestRule.activity==null)
      }
  }
  </code></pre>
  
  <p>Actually i got a test failed because of the following exception : </p>
  
  <blockquote>
    <p>android.support.test.espresso.NoActivityResumedException: Pressed back and killed the app</p>
  </blockquote>
  
  <p>I've seen some propositions in stackoverflow about using a try/catch block but i'm wondering if there is a more proper way to do this ?</p>
  
  <p><a href="https://stackoverflow.com/questions/36540549/how-to-test-android-app-has-closed-with-espresso">How to test android app has closed with Espresso</a></p>
  
  <p><a href="https://stackoverflow.com/questions/43040925/android-espresso-test-with-pressback">Android - Espresso test with pressBack</a></p>
  
  <p>EDIT: 
  So it seems that this template is the way to go :</p>
  
  <pre><code>try {
      pressBack();
      fail("Should have thrown NoActivityResumedException");
  } catch (NoActivityResumedException expected) { 
  }
  </code></pre>