Error "The @Rule must be public" in Android tests with Kotlin
Hello everyone! I'm new to Android development in Kotlin and trying to write my first UI tests using Espresso. Based on examples from the internet, I created a test class and used ActivityTestRule to launch the Activity. Here's my code:\n\n```kotlin\n@RunWith(AndroidJUnit4::class)\nclass MainActivityTest {\n\n @Rule\n @JvmField\n val activityRule = ActivityTestRule(MainActivity::class.java)\n\n @Test\n fun testButtonClick() {\n onView(withId(R.id.button)).perform(click())\n onView(withText("Hello")).check(matches(isDisplayed()))\n }\n}\n```\n\nBut when I run the test, I get the error: "The @Rule must be public". I've tried different options: removed `@JvmField`, made the Rule a public field, but still get the error. What could be the problem? I'm using the latest
No answers yet.
Log in to leave an answer