Test run failed: Instrumentation run failed due to 'Process crashed.' when testing multiple Android activity

拈花ヽ惹草 提交于 2019-12-01 02:41:00

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.

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.

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.

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();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!