I created a default empty project on Android Studio 2.1.2 with API 24. In the sample project, Google offers a depreciated class Applica
The new androidTest example that the beta version of Android Studio 2.2 generates, look like this:
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("org.mypackage", appContext.getPackageName());
}
}
Just like the deprecation warning suggests, the new instrumentation tests should use InstrumentationRegistry
instead of extending from AndroidTestCase
. Run them with AndroidJUnit4
.
The relevant dependencies
section in build.gradle
looks like this:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})