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

前端 未结 4 1209
说谎
说谎 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.

提交回复
热议问题