title: Expecting an exception in Android Espresso test - fails
body: <p>I am writing tests in Espresso for my Android application using Kotlin.
  I want to expect an exception as in the unit test and pass the test if such an exception is found.</p>
  
  <p>I had a test that was checking for the Intent extras format.
  In the implementation I have thrown an exception after getting an incorrect value in the intent.
  I want to pass the test is this exception is thrown. Running the test results with a "Test failed" and <code>java.lang.IllegalArgumentException</code> which is the same as I am trying to catch.</p>
  
  <p>I tried with this annotation at first:</p>
  
  <p><code>@Test(expected = IllegalArgumentException::class)</code></p>
  
  <p>Then I tried with a <code>org.jetbrains.kotlin:kotlin-test</code> dependency and the following assertion:</p>
  
  <pre><code>assertFailsWith&lt;java.lang.IllegalArgumentException&gt; {
      val activityIntent = Intent()
      activityIntent.putExtra("extra_connection_number", intentExtraConnectionNumber)
      activityRule.launchActivity(activityIntent)
  }
  </code></pre>
  
  <p>What may be also important is that the exception is thrown in the <code>onCreateView</code>starting as so:</p>
  
  <pre><code>@Throws(java.lang.IllegalArgumentException::class)
  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
      val layout = inflater.inflate(R.layout.configuration_fragment, container, false)
      var connectionNumber: Int? =
          activity!!.intent.getIntExtra(resources.getString(R.string.extra_connection_number), -1)
      if (connectionNumber == -1) {
          throw IllegalArgumentException()
      }
  (...)
  </code></pre>
  
  <p>The intent is created with the given extra, and it is failing in a place I wanted it to fail. But the thrown exception is not caught by the Espresso.
  Why? What am I missing?</p>
  
  <p>I am aware it may be incompatible with Espresso, but I cannot find a right documentation helping me with the problem.</p>