Skip to content

Annotations in espresso

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

Annotation - AndroidJUnit4ClassRunner

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

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