我正在使用Espresso运行 android UI 测试,在包含所有必需的依赖项并创建所需的类测试之后,运行它时给我错误:
java.lang.Exception: Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)
并且肯定它是一个内置类,所以我不必更改它,即使我尝试创建一个自定义类,但这导致我遇到其他问题,除非删除我添加的额外构造函数,否则这些问题将无法解决自定义类,最终导致我遇到同样的问题。
我的测试课:
@RunWith(AndroidJUnit4.class)
public class CreateTest {
@Rule
public ActivityTestRule mainActivityTest = new ActivityTestRule<>(MainActivity.class);
@Before
public void setUp() throws Exception {
Context context = InstrumentationRegistry.getContext();
}
@Test
public void clickAdd(){
Espresso.onView(withId(R.id.button))
.perform(click());
intended(hasComponent(new ComponentName(getTargetContext(), SecondActivity.class)));
}
}
依赖项:
compile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile ('com.android.support.test:runner:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile ('com.android.support.test:rules:0.5', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile('com.android.support.test.espresso:espresso-intents:2.2.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
ps如果有可用的测试 api,我已经准备好使用另一个测试 api,但我搜索并一无所获。