Coming back to Android dev after a year and I'm all confused on espresso again -_-
I'm just trying to setup a simple espresso test and it fails saying:
java.lang.RuntimeException: No activities found. Did you forget to launch the activity by calling getActivity() or startActivitySync or similar?
and indeed, I don't see the app being launched. Here is the code:
@RunWith(AndroidJUnit4::class)
@LargeTest
class EfficioTest {
@get:Rule @JvmField var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
private fun getActivity() = activityRule.activity
@Test fun testInitState() {
onView(withId(R.id.store_spinner)).check(matches(isDisplayed()))
}
}
MainActivity is in the manifest and is working fine when launching using the launcher.
What am I missing?
Found it! Changed:
@get:Rule @JvmField var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
To:
@Rule @JvmField var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
(removed get:)
For me
@get:Rule
val activityRule = ActivityScenarioRule(MainActivity::class.java)
has worked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With