title: Running an instrumented test in Android Studio without simulating user actions
body: <p>I have written some code that manipulates MotionEvent instances, and want to write a unit test for it.</p>
  <p>The unit test needs to validate my manipulations only; it does not need to simulate any user actions.</p>
  <p>I understand it needs to be an instrumented test to be able to use the methods of MotionEvent; I need the actual methods, not any mocking.</p>
  <p>I have defined an instrumented test in the directory src/androidTest/...; however, it still throws the exception</p>
  <blockquote>
  <p>java.lang.RuntimeException: Method obtain in android.view.MotionEvent not mocked.</p>
  </blockquote>
  <p>My build.gradle file for the module has the following entries:</p>
  <pre><code>defaultConfig {
      ...
      testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
  }
  ...
  dependencies {
      implementation 'androidx.appcompat:appcompat:1.3.0'
      implementation 'com.google.android.material:material:1.3.0'
      implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
      testImplementation 'junit:junit:4.+'
      androidTestImplementation 'androidx.test.ext:junit:1.1.2'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
  }
  </code></pre>
  <p>The imports in my test class are as follows:</p>
  <pre><code>import android.view.MotionEvent;
  import org.junit.Test;
  import static org.junit.Assert.*;
  </code></pre>
  <p>How can I run this test?</p>