Android Toast累积测试 [英] Android Toast Accumulation Testing

查看:98
本文介绍了Android Toast累积测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Like many others, i've been trying to solve the problem of toast accumulation.

  • 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

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

I finally decided to keep track of the current displayed toast and cancel it when another arrives (there's some more logic involved), but i could have use only one toast and change it message. What i want to know is this... Is there a way to TEST this behaviour? Im currently using Robotium and tried different things, but unfortunately the methods to check for toasts (solo.waitForText and solo.searchForText) aren't helping me as i can't make something like

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

有人做过这样的事情吗?有没有办法使用Robotium对此进行测试?在用其他东西吗?

Has anyone done something like this? Is there a way to test this using Robotium? using somethig else?

推荐答案

您可以使用机械手条件来等待文本消失.这是我使用的一种方法.

You can use a robotium condition to wait for the text to disappear. Here's a method I use for that.

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));
}

这篇关于Android Toast累积测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆