我可以在指定类时运行检测测试。
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)
我的所有检测测试都位于com.application.instrumentation
包中。当我尝试在此包中运行所有测试时,检测无法找到任何测试。
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
AndroidStudio
相同 - 我可以在特定的类中运行测试,而不是在整个包中运行。
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
版本为1.2.2
。
测试依赖关系:
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'
}
可用的工具:
adb shell pm list instrumentation
instrumentation:com.application.debug.test/android.support.test.runner.AndroidJUnitRunner (target=com.application.debug)
答案 0 :(得分:1)
我相信这是因为JUnit4风格的测试类不应该扩展ActivityInstrumentationTestCase2<BaseActivity>
。只需省略该部分,不要扩展任何类,请参阅例如this example