I'm able to run the instrumentation tests just if I specify the class.
adb shell am instrument -w -e class com.application.instrumentation.BaseActivityTest com.application.debug.test/android.support.test.runner.AndroidJUnitRunner
com.application.instrumentation.BaseActivityTest:.
Time: 2.204
OK (1 test)
All my instrumentation tests located in com.application.instrumentation
package. When I'm trying to run all tests in this package, instrumentation can't locate any test.
adb shell am instrument -w -r -e package com.application.instrumentation com.application.debug.test/android.support.test.runner.AndroidJUnitRunner
INSTRUMENTATION_RESULT: stream=
Time: 0
OK (0 tests)
INSTRUMENTATION_CODE: -1
Same for AndroidStudio
- I'm able to run tests in specific class and not in the whole package.
BaseActivityTest.java
@RunWith(AndroidJUnit4.class)
@LargeTest
public class BaseActivityTest
extends ActivityInstrumentationTestCase2<BaseActivity> {
private BaseActivity mActivity;
public BaseActivityTest() {
super(BaseActivity.class);
}
@Before
public void setUp() throws Exception {
super.setUp();
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
mActivity = getActivity();
}
@Test
public void checkPreconditions() {
assertThat(mActivity, notNullValue());
// Check that Instrumentation was correctly injected in setUp()
assertThat(getInstrumentation(), notNullValue());
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
}
AndroidStudio
version is 1.2.2
.
Test dependencies:
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
Available instrumentations:
adb shell pm list instrumentation
instrumentation:com.application.debug.test/android.support.test.runner.AndroidJUnitRunner (target=com.application.debug)
I believe that's because JUnit4-style test classes are not supposed to extend
ActivityInstrumentationTestCase2<BaseActivity>
. Simply omit that part and do not extend any class, see e.g. this example.