11package com.stepstone.xrunner.sample
22
3+ import androidx.lifecycle.Lifecycle
4+ import androidx.test.core.app.ActivityScenario
35import androidx.test.espresso.Espresso.onView
46import androidx.test.espresso.action.ViewActions.click
57import androidx.test.espresso.assertion.ViewAssertions.matches
68import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
79import androidx.test.espresso.matcher.ViewMatchers.withId
810import androidx.test.espresso.matcher.ViewMatchers.withText
911import androidx.test.ext.junit.runners.AndroidJUnit4
10- import androidx.test.rule.ActivityTestRule
1112import org.hamcrest.Matchers.not
13+ import org.junit.*
1214import org.junit.Assert.assertTrue
13- import org.junit.Ignore
14- import org.junit.Rule
15- import org.junit.Test
1615import org.junit.runner.RunWith
1716
1817@RunWith(AndroidJUnit4 ::class )
1918class MainActivityTest {
2019
21- @get:Rule
22- val rule = ActivityTestRule (MainActivity ::class .java)
20+ private lateinit var scenario: ActivityScenario <MainActivity >
21+
22+ @Before
23+ fun launch () {
24+ scenario = ActivityScenario .launch(MainActivity ::class .java).also {
25+ it.moveToState(Lifecycle .State .RESUMED )
26+ }
27+ }
2328
2429 @Test
2530 fun dummy_text_should_be_hidden_by_default () {
26- onView(withId(R .id.dummy_text_view )).check(matches(not (isDisplayed())))
31+ onView(withId(R .id.dummyTextView )).check(matches(not (isDisplayed())))
2732 }
2833
2934 @Test
@@ -38,11 +43,16 @@ class MainActivityTest {
3843 onView(withId(R .id.fab)).perform(click())
3944
4045 // then
41- onView(withId(R .id.dummy_text_view )).check(matches(withText(" XRunner" )))
46+ onView(withId(R .id.dummyTextView )).check(matches(withText(" XRunner" )))
4247 }
4348
4449 @Test
4550 fun failing_test () {
4651 assertTrue(false )
4752 }
53+
54+ @After
55+ fun cleanup () {
56+ scenario.close()
57+ }
4858}
0 commit comments