Android 测试 - ActivityInstrumentationTestCase2 存在问题?
我正在使用 Robotium 和 ActivityInstrumentationTestCase2 运行 Android 版 UIAutomation。我有一个包含 5 个测试的测试套件。 有时我的测试会随机崩溃,因为一旦前一个测试尚未结束,测试就开始了。 有办法避免这种情况吗?是否可以在每次测试之前手动添加 10 秒的延迟来避免这个可怕的烦人的错误?
编辑:
public class MyTest<T extends RoboActivity> extends ActivityInstrumentationTestCase2<T>
{
protected Solo solo;
@Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
try {
solo.finalize();
}
catch (Throwable e) {
Assert.fail(e.getMessage()+ e.toString());
e.printStackTrace();
}
super.tearDown();
}
}
I am running UIAutomation for android using Robotium and ActivityInstrumentationTestCase2. I have a test suite with 5 tests.
Sometimes my test randomly crash because a test starts, once the previous test has not ended yet.
Is there a way to avoid this? is it possible to manually add a 10 second delay before every test to get away from this horrible annoying bug?
EDIT:
public class MyTest<T extends RoboActivity> extends ActivityInstrumentationTestCase2<T>
{
protected Solo solo;
@Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
try {
solo.finalize();
}
catch (Throwable e) {
Assert.fail(e.getMessage()+ e.toString());
e.printStackTrace();
}
super.tearDown();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这可行:
似乎 waitFor* 方法比“睡眠”更好地管理这一点
http://robotium.googlecode .com/svn/doc/com/robotium/solo/Solo.html#waitForActivity(java.lang.Class, int)
Maybe this could work :
Seems that waitFor* methods are managing that better than a "sleep"
http://robotium.googlecode.com/svn/doc/com/robotium/solo/Solo.html#waitForActivity(java.lang.Class, int)
我的测试的构建、拆卸等略有不同,但运行良好(见下文)。我必须添加睡眠来解决一些不确定的测试失败问题。
My tests's construction, teardown, etc. are slightly different and works well (see below). I had to add a sleep to work around some non-deterministic test-failures.