Skip to content

Annotations in espresso

Devrath edited this page May 17, 2021 · 10 revisions
Title
AndroidJUnit4
ActivityTestRule

Annotation - AndroidJUnit4

@RunWith(AndroidJUnit4::class)
class MainActivityTest {
    @Test
    fun greet() {
    }
}

AndroidJUnit4::class --> This specifies the tests written in this class is an android test

ActivityTestRule

@RunWith(AndroidJUnit4ClassRunner::class)
class MainActivityTest {

    @Rule @JvmField
    var activityRule = ActivityTestRule<MainActivity>(MainActivity::class.java)

    @Test
    fun greet() { }
}
  • ActivityTestRule is used to tell espresso which activity to run before running the tests in the test class.
  • By this rule the activity is run every time before each test.
  • @JvmField, this is required to make the @Rule work.
Clone this wiki locally