Geob-o-matic
Geob-o-matic

Reputation: 6079

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?

Upvotes: 7

Views: 6493

Answers (2)

Patricia
Patricia

Reputation: 2865

For me

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

has worked

Upvotes: 2

Geob-o-matic
Geob-o-matic

Reputation: 6079

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

Upvotes: 9

Related Questions