Reputation: 1699
I'm trying to keep my activity alive after a certain test has finished with AndroidJUnit4. The reason why I want to do this is that sometimes I just want to see how the UI looks like and how the haptic feels like. For purposes like that, I don't want to build the whole app and navigate to the desired sites.
I read, that it's possble to override the tearDown() in order to prevent closing the activity.
Though the InstrumentationTestCase is deprecated and Android suggests to use the InstrumentationRegistry and that new tests should be written with the new Testing Support Library.
How does it work to keep the activity alive after the test finished by using this new library?
Upvotes: 1
Views: 287
Reputation: 1699
I found a solution that works for me. If you have better suggestions, please let me know.
AndroidJUnit4 does have tearDown and setUp, though it's not an override. It must be implemented by using an annotation:
@Before
public void setUp() throws Exception {
//do something
}
@After
public void tearDown() throws Exception {
//do something
}
In order to keep the activity alive after the test passed, I let the thread wait in the tearDown method:
@After
public void tearDown() throws Exception {
synchronized (this) {
wait();
}
}
If you like to wake up the thread after a certain time (but I would suggest to use Thread.sleep() in that case) or if you like to trigger a wake up call, you can easily combine the synchronised block with a lock.
Upvotes: 1