Search code examples
androidtestingtoastfunctional-testingrobotium

Android Toast Accumulation Testing


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

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?


Solution

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