Espresso測試toast

之前玩Appium的時候,因為底層實作為uiautomator,那時候沒找到測試toast的方法,現在玩uiautomator + Espresso的靈活搭配,而在Espresso上有找到測試toast的方式。

onView(withText(R.string.my_toast_message))
        .inRoot(withDecorView(not(getActivity().getWindow().getDecorView())))
        .check(matches(isDisplayed()));

參考
Android Espresso: How to check that Toast message is NOT shown? 

留言