Reputation: 16066
I suspect my question is the same as this one, but the code there is incomplete and I must be missing something.
Here's my test class:
@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())
}
}
The test fails with the following error:
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)
What am I doing wrong here?
Upvotes: 1
Views: 587
Reputation: 10352
You are not doing anything wrong. It is a shortcoming of the AndroidJUnit4
test runner that does not execute rules with @ClassRule
annotations. You can remove the @RunWith
annotation and see the rule being executed but crashing.
Upvotes: 0