gpt4 book ai didi

android - "Test failed to run to completion. Reason: ' 运行多个测试用例时由于 'Process crashed.' 导致仪器运行失败

转载 作者:太空宇宙 更新时间:2023-11-03 10:20:02 25 4
gpt4 key购买 nike

我写了一个测试项目来测试一个android应用程序(Application Under Test是我自己的项目)。我在控制台和 Junit View 中遇到以下故障。

测试未能完成。原因:“由于‘进程崩溃’,检测运行失败。”。检查设备日志猫以获取详细信息

但是 log-cat 没有任何异常。日志似乎与应用程序的成功简单运行相同。当我调试测试时,它在以下行的 teardown() 方法中失败:

        solo.finishOpenedActivities();

但是 log-cat 上没有任何反射(reflect)。此外,对于所有测试运行,这种失败并不一致。有时它在第一个测试用例之后失败,有时在第一个测试用例之前失败。

public class MainActivityTest extends
ActivityInstrumentationTestCase2<MainActivity> {

private Solo solo;

public MainActivityTest() throws ClassNotFoundException {
super(MainActivity.class);
}

@Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}

public void testActivityProperlyDisplayed() throws Exception {

getInstrumentation().waitForIdleSync();
if (getActivity().getActionBar() != null) {
assertFalse("ActionBar is shown", getActivity().getActionBar()
.isShowing());
} else {
throw new AssertionFailedError("ActionBar not showing");
}
}

public void test2(){}
public void test3(){}
// and so on

@Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}

}

Robotium 版本为5.2.1,已正确导入到项目中。也成功运行其他应用程序。这是在控制台中打印的行

[2014-07-29 14:19:38 - XMClientTest] Launching instrumentation android.test.InstrumentationTestRunner on UOQ1GYHIQ4
[2014-07-29 14:19:43 - XMClientTest] Sending test information to Eclipse
[2014-07-29 14:19:49 - XMClientTest] Test run failed: Instrumentation run failed due to 'Process crashed.'
[2014-07-29 14:19:49 - XMClientTest] Test run finished

最佳答案

我遇到了问题。仪器测试无法测试具有 System.exit(0) 处理语句的应用程序。

正如我们所知,在每个测试用例完成后调用 tearDown() 函数,然后我们编写 solo.finishOpenedActivities() 来完成所有打开的 Activity (推荐)。

当调用 solo.finishOpenedActivities() 时,它会调用已打开 Activity 的 onDestroy() 函数。我在 onDestroy() 方法中使用 System.exit(0) 导致停止无法由 Instrumentation runner 重新初始化的 Dalvik 虚拟机(因此完成所有对象)。

因此尽量避免使用 System.exit(0); 来对您的应用程序进行单元测试。

关于android - "Test failed to run to completion. Reason: ' 运行多个测试用例时由于 'Process crashed.' 导致仪器运行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25011788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com