Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kotlin + espresso: No activities found

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?

like image 685
Geob-o-matic Avatar asked Sep 11 '16 14:09

Geob-o-matic


2 Answers

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:)

like image 61
Geob-o-matic Avatar answered Sep 27 '22 21:09

Geob-o-matic


For me

 @get:Rule
    val activityRule = ActivityScenarioRule(MainActivity::class.java)

has worked

like image 30
Patricia Avatar answered Sep 27 '22 23:09

Patricia