I am writing a test to check if a custom Toast
is being shown. The Toast is not being constructed and shown in an Activity
instance. I have a created a class that has access to the 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.