【发布时间】:2020-05-15 14:56:57
【问题描述】:
我想使用 Espresso 测试 Toast 消息,但是当我调用显示 toast 的方法时,没有显示 toast。
它在我正常运行应用程序时显示,但是当我运行测试时,没有显示 toast。
fun Context.showMessage(@StringRes message:Int){
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
我在 TestFragment 的 showMessage 方法中调用 showMessage(),该方法在 FragmentScenario 的 onFragment 中调用
override fun showMessage(message: Int) {
context?.showMessage(message)
}
val scenario = launchFragmentInContainer<TestFragment>()
scenario.onFragment {
it.showMessage(R.string.test_string)
onView(withText(it.context.getString(R.string.test_string))
.inRoot(ToastMatcher())
.check(matches(isDisplayed()))
}
测试用例卡在了
check(matches(isDisplayed()))
我猜是因为没有显示吐司。
【问题讨论】:
-
我现在遇到了这个问题。你找到解决办法了吗?
标签: android testing android-espresso instrumentation android-instrumentation