【问题标题】:Android Toast Accumulation TestingAndroid Toast 累积测试
【发布时间】:2014-01-21 20:53:49
【问题描述】:

和许多其他人一样,我一直在努力解决吐司堆积的问题。

我最终决定跟踪当前显示的 toast 并在另一个到达时取消它(涉及更多逻辑),但我可以只使用一个 toast 并更改它的消息。我想知道的是……有没有办法测试这种行为?我目前正在使用 Robotium 并尝试了不同的方法,但不幸的是,检查 toast 的方法(solo.waitForTextsolo.searchForText)对我没有帮助,因为我无法制作类似的东西

assertTrue(solo.waitForText(text));
//maybe even some sleep here
assertFalse(solo.searchText(text);

有人做过这样的事吗?有没有办法使用 Robotium 进行测试?用别的东西?

【问题讨论】:

  • 没有帮助是什么意思?测试失败了吗?会发生什么?
  • 没错。抱歉,测试在第二次断言时失败,因为它与 toast 中的文本匹配,当您希望 toast 消失时。有意义吗?
  • 等到 toast 消失后再进行第二次断言。类似于:while(solo.waitForText("my toast"); 然后 assertFalse(..)
  • 其实 while(solo.searchText("my toast"); 在这种情况下使用会更好。
  • 嗯,有趣...您尝试过这种方法吗?我的意思是在工作代码中。我想知道如果 while 弹出来是否会捕获许多累积的吐司……因为这是我们正在测试的对象。

标签: android testing toast functional-testing robotium


【解决方案1】:

您可以使用机器人条件来等待文本消失。这是我使用的一种方法。

private void waitForTextToDisappear(final String text, int wait) {
    Condition textNotFound = new Condition() {

        @Override
        public boolean isSatisfied() {
            return !solo.searchText(text);
        }
    };
    assertTrue("Text gone: " + text, solo.waitForCondition(textNotFound, wait));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多