I am using Espresso/Kotlin to run tests for our Android Application and I want to run the setup once for all tests in the given test class.
I created a companion object to launch the application once (which it does), however it then closes and doesn't stay open while each test runs.
How can I have it launch the application, run all the tests in the test class, then close the application?
I also tried the following, but it still launches once then closes, then tries running the tests:
This is by design.
This rule provides functional testing of a single activity. The activity under test will be launched before each test annotated with @Test and before any method annotated with @Before. It will be terminated after the test is completed and all methods annotated with @After are finished. The activity under test can be accessed during your test by calling ActivityTestRule.getActivity().
Source: JUnit4 Rules
You might be able to get around it by making a custom rule. Otherwise, you could create a single @Test
and put each of your assertions inside it. To keep your general format, you could put your assertions in separate private functions.
For example:
@Test
fun testLoginPage() {
testLoginButtonIsDisplayed()
// call other private functions
}
private fun testLoginButtonIsDisplayed() {
loginPage.loginButton.check(matches(isDisplayed()))
}
// add other private functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With