简体   繁体   English

Android测试是否显示吐司

[英]Android Test if toast is shown

I am writing a test to check if a custom Toast is being shown. 我正在编写测试以检查是否显示了自定义Toast The Toast is not being constructed and shown in an Activity instance. Toast未在Activity实例中构建和显示。 I have a created a class that has access to the Context . 我创建了一个可以访问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
   }
}

How should I go about testing this? 我应该如何测试呢? I am using Espresso. 我正在使用义式浓缩咖啡。

What about 关于什么

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

?

If there is such need you can create matcher like this 如果有这种需要,您可以像这样创建匹配器

http://baroqueworksdev.blogspot.de/2015/03/how-to-check-toast-window-on-android.html 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