I\'ve got an issue with testing my android application.
I have 2 testCase class, if I execute them separately, there is no problem, the tests run until the end. But if I
I also encountered similar problem when running my android instrumentation. Eventually i ended up with conclusion that the problem is of System.exit(0).
Now, the reason, why it causes the problem According to its documentation
Causes the VM to stop running and the program to exit.
When System.exit(0) gets executed all other code written after this code are skipped and activity class gets finalized and go for Garbage Collected. Since Instrumentation rely on activity life-cycle method, the activity class is Garbage collected the there is no chance of calling its methods if object itself does not exist.
Hence avoid using System.exit(0) if you want to do unit testing of application, use finish() method instead.
I used to get this error when I used System.exit(0) on my test Activity's onFinish like below:
@Override
public void finish() {
super.finish();
System.exit(0);
}
So check your Main activity's onFinish method.
In case anyone else is also using Robotium and saw the error: I forgot to tearDown
the opened activity, and this resulted in the error as described above.
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
I encountered this error as well. However, I ended up finding that my test suite did run, the only problem was that an assert in my test code failed.
I looked into LogCat and filter out those Tagged "TestRunner" messages and found the assertion failure message among other testing logs.