Android 测试 - ActivityInstrumentationTestCase2 有问题吗?

标签 android ui-automation robotium

我正在使用 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();
    }
}

最佳答案

也许这可行:

mSolo = new Solo(getInstrumentation(), getActivity());
mSolo.waitForActivity(AccountDetail.class);

似乎 waitFor* 方法比“ sleep ”管理得更好 http://robotium.googlecode.com/svn/doc/com/robotium/solo/Solo.html#waitForActivity(java.lang.Class , 整数)

关于Android 测试 - ActivityInstrumentationTestCase2 有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8495048/

相关文章:

android - 如何检查 Robotium 测试中剪贴板中是否存在文本?

java - Android 编程中的传入短信列表

android - 无法识别为内部或外部命令错误

javascript - 如何知道 nightwatch.js 中该行已执行?

c# - UI 自动化 - #32770(对话框)在 Insepct.exe 中显示,但不在 VisualUIAVerifyNative.exe 中显示

关于 getCurrentActivity() 延迟的 android robotium

android - View 中的位图未在 Android 上显示

android - 方向改变 : reloading layouts from resources

android - 如何将通知作为通知而不是正在进行的通知