繁体   English   中英

Android测试是否显示吐司

[英]Android Test if toast is shown

我正在编写测试以检查是否显示了自定义Toast Toast未在Activity实例中构建和显示。 我创建了一个可以访问Context

public class ToastHandler{
    private Context context;
    public ToastHander(Context context){
       this.context = context;
    }

   public createToast(DataStructure data){
      // Create and show Custom Toast using data and context
   }
}

我应该如何测试呢? 我正在使用义式浓缩咖啡。

关于什么

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

如果有这种需要,您可以像这样创建匹配器

http://baroqueworksdev.blogspot.de/2015/03/how-to-check-toast-window-on-android.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM