我怀疑我的问题和这个问题一样,但是那里的代码不完整,我一定遗漏了一些东西。
这是我的测试课:
@RunWith(AndroidJUnit4::class)
class MyTest {
companion object {
@ClassRule
@JvmField
val activityTestRule = ActivityTestRule(MainActivity::class.java, true, true)
}
@Test
fun verifySomething() {
onView(withId(R.id.something)).perform(click())
}
}
测试失败并出现以下错误:
java.lang.RuntimeException: No activities found. Did you t to launch the activity by calling getActivity() or startActivitySync or similar?
at android.support.test.espresso.base.RootViewPicker.waitForAtLeastOneActivityToBeResumed(RootViewPicker.java:169)
at android.support.test.espresso.base.RootViewPicker.get(RootViewPicker.java:83)
at android.support.test.espresso.ViewInteractionModule.provideRootView(ViewInteractionModule.java:77)
at android.support.test.espresso.ViewInteractionModule_ProvideRootViewFactory.proxyProvideRootView(ViewInteractionModule_ProvideRootViewFactory.java:35)
at android.support.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:24)
at android.support.test.espresso.ViewInteractionModule_ProvideRootViewFactory.get(ViewInteractionModule_ProvideRootViewFactory.java:10)
at android.support.test.espresso.base.ViewFinderImpl.getView(ViewFinderImpl.java:62)
at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:218)
at android.support.test.espresso.ViewInteraction.access$100(ViewInteraction.java:63)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:153)
at android.support.test.espresso.ViewInteraction$1.call(ViewInteraction.java:150)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我在这里做错了什么?