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

前端 未结 4 1200
说谎
说谎 2021-01-11 10:00

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

相关标签:
4条回答
  • 2021-01-11 10:47

    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.

    0 讨论(0)
  • 2021-01-11 10:49

    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.

    0 讨论(0)
  • 2021-01-11 10:57

    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();
    }
    
    0 讨论(0)
  • 2021-01-11 10:58

    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.

    0 讨论(0)
提交回复
热议问题