Run espresso in ActivityInstrumentationTestCase2
<p>I have written some test cases but when I try to include espresso in it, it shows <code>java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation.</code></p>

<p>I know I should migrate to junit 4 but I really dont want to change all the tests.</p>

<p>Here is the test class:</p>

<pre><code>public class MainActivityTest extends ActivityInstrumentationTestCase2&lt;MainActivity&gt; {

    private Activity activity;

    public MainActivityTest() {
        super(MainActivity.class);
    }

    @Before
    protected void setUp() throws Exception {
        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        activity = getActivity();
    }

    @Test
    public void testEmptyField() {
        onView(withId(R.id.editText)).perform(typeText(""));

        onView(withId(R.id.buttonVerify)).perform(click());

        onView(withText("Please input text")).check(matches(isDisplayed()));
    }

}
</code></pre>

<p>Here are the dependencies I've included:</p>

<pre><code>dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':UniversalImageLoader')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    androidTestCompile 'com.android.support.test:runner:0.4'
    androidTestCompile 'com.android.support.test:rules:0.4'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
}
</code></pre>