Android Toast Accumulation Testing

早过忘川 提交于 2019-12-10 11:45:43

问题


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

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

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


回答1:


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


来源:https://stackoverflow.com/questions/21268886/android-toast-accumulation-testing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!