【发布时间】:2014-01-21 20:53:49
【问题描述】:
和许多其他人一样,我一直在努力解决吐司堆积的问题。
- How to prevent Multiple Toast Overlaps
- toast issue in android
- Cancelling an already open toast in Android
- Best way to avoid Toast accumulation in Android
我最终决定跟踪当前显示的 toast 并在另一个到达时取消它(涉及更多逻辑),但我可以只使用一个 toast 并更改它的消息。我想知道的是……有没有办法测试这种行为?我目前正在使用 Robotium 并尝试了不同的方法,但不幸的是,检查 toast 的方法(solo.waitForText 和 solo.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