Issue
So I want to make my Practice test suite sequential, meaning, tests build on top of each other. Currently its restarting the app every time a test finishes, but I would like for the app to remain open.
I've tried using @BeforeAll but its not working, it makes me add JUnit5.4 to the class path and even after I do It still red, meaning It doesn't like it for some reason.
Anyway, I think its the rule, I think the activity is making my tests restart every time each one finishes, id like it to not do that or if there's a different test rule that I can use that doesn't do that then that would be magnificent.
class Practice {
@get:Rule
val activityRule = ActivityScenarioRule(MainActivity::class.java);
@Before
fun setUp() {
onView(withText("Log In With Mobile Code")).perform(click());
onView(withResourceName("txtMobileAccessCode")).check(matches(withText("Company Code
or\nMobile Access Code")));
}
@Test
fun clickOnEnterAccessCode() {
onView(withResourceName("txtCodeEntry")).perform(typeText("CodeGoesHere"));
}
@Test
fun enterCode() {
onView(withResourceName("btnCodeSubmit")).perform(click());
}
}
Solution
The problem is in using an ActivityScenarioRule to drive things; this calls ActivityScenario.close() by default at the end of each test, which will reset your app.
Instead, look at controlling the activity's lifecycle yourself by dealing directly with ActivityScenario. There will be more overhead, but you'll have much more control over things and be able to not call close() until you want to.
From the Android Developer Docs the syntax you're looking for is the following:
val scenario = launchActivity<MainActivity>()
Answered By - Mike Collins
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.