Reputation: 27727
Suppose you are constructing a test case for the Android platform using a class with a signature like:
public class AccountTest extends ActivityInstrumentationTestCase2<MainActivity> { ... }
Say we have a test method like this using the Robotium framework:
public void testCreateAccount() {
solo.clickOnButton("Add Account");
solo.clickOnButton("Next");
...
}
When the test case completes, the instrumented activity is swiftly killed. Is there any way to keep it alive upon termination, at least for the purpose of determining what you want to do next and coding the next few lines?
Upvotes: 3
Views: 2098
Reputation: 77
I have the same problem.Finally i use Sleep().
while(true)
{
Thread.Sleep(1000);
// do other things when the main thread wake
}
you can put the above code in arbitrary test method,then the instrument Activity
will not end.
Hope it helps you.
Upvotes: 0
Reputation: 27727
As it turns out, it is easy to accomplish essentially what I want by using the Nativedriver library:
http://code.google.com/p/nativedriver/
Omitting driver.quit()
at the end of the test case keeps the activity alive, which is very handy when developing the test case initially.
Upvotes: 1
Reputation: 41126
Android JUnit Test is built on top of JUnit, as a consequence, it obeys the basic rules of JUnit test life cycle:
When the test case completes, the instrumented activity is swiftly killed.
See the source code of ActivityInstrumentationTestCase2 for the reason:
@Override
protected void tearDown() throws Exception {
// Finish the Activity off (unless was never launched anyway)
Activity a = super.getActivity();
if (a != null) {
a.finish();
setActivity(null);
}
// Scrub out members - protects against memory leaks in the case where someone
// creates a non-static inner class (thus referencing the test case) and gives it to
// someone else to hold onto
scrubClass(ActivityInstrumentationTestCase2.class);
super.tearDown();
}
Is there any way to keep it alive upon termination, at least for the purpose of determining what you want to do next and coding the next few lines?
Possible workarounds are:
In either approach, you should implement your teardown() method carefully to avoid memory leaks.
Hope this helps.
Upvotes: 2