【发布时间】:2015-04-27 12:46:29
【问题描述】:
我现在正在我的功能测试中工作,其中一个我必须测试没有显示 toast 消息。考虑到这是我用来检查是否显示 toast 消息的代码(此代码有效):
onView(withText(R.string.my_toast_message))
.inRoot(withDecorView(not(getActivity().getWindow().getDecorView())))
.check(matches(isDisplayed()));
您可以在下面找到我用来检查 Toast 消息是否未显示的代码(它们都不起作用):
方法一:
onView(withText(R.string.error_invalid_login))
.inRoot(withDecorView(not(getActivity().getWindow().getDecorView())))
.check(matches(not(isDisplayed())));
方法二:
onView(withText(R.string.error_invalid_login))
.inRoot(withDecorView(not(getActivity().getWindow().getDecorView())))
.check(doesNotExist());
任何关于如何检查 toast 消息是否未显示的想法将不胜感激:)
【问题讨论】:
-
您的第二种方法对我来说似乎是正确的。如果你说它不起作用,你会得到什么样的意外行为?
-
第二种方法对我有用。正如@apppoll 所说,在测试中运行第二种方法的结果是什么?
-
我的方法二出现了 NoMatchingRootException,所以它对我也不起作用,你让它起作用了吗?
标签: android testing functional-testing android-espresso