【发布时间】:2017-06-21 06:47:39
【问题描述】:
1) 所有正在测试的设备/模拟器都禁用了动画。
2) 我有一个 @BeforeClass 来构建我的 Credentials 对象。
3) 我有一个 IntenServiceIdlingResource 和一个 EventBusIdlingResource,在 @Before 中注册。
4) 当登录按钮被点击时,IntentService 被触发。在这种情况下,服务器(模拟服务器)返回 500 错误。该信息通过 greenrobot 的 EventBus 从 IntentService 发送回 UI,并显示带有错误消息的 Snackbar。
这是测试代码:
@Test
public void a_userNamePasswordTest() throws Exception {
// email input
ViewInteraction userNameView = onView(withId(R.id.email));
// verify it's on screen and enabled
userNameView.check(matches(isDisplayed())).check(matches(isEnabled()));
// set the username
userNameView.perform(scrollTo(), replaceText(credentials.username), closeSoftKeyboard());
// password input
ViewInteraction passwordView = onView(withId(R.id.password));
// verify it's on screen and enabled
passwordView.check(matches(isDisplayed())).check(matches(isEnabled()));
// set the password.
passwordView.perform(scrollTo(), replaceText(credentials.password), closeSoftKeyboard());
// sign in button
ViewInteraction signInButton = onView(withId(R.id.email_sign_in_button));
// verify the button
signInButton.check(matches(allOf(
isDisplayed(), isEnabled(), withText("Sign In"), withContentDescription("Sign In")
)));
// clickity click the button
signInButton.perform(scrollTo(), click());
// verify the snackbar text
onView(withText(startsWith("Server Error: 500"))).check(matches(isDisplayed()));
}
这是我通常遇到的异常:
SignInExceptionTest > a_userNamePasswordTest[Nexus_6P_API_23(AVD) - 6.0] 失败 android.support.test.espresso.NoMatchingViewException:层次结构中找不到匹配的视图:带有文本:以开头的字符串 “服务器错误:500”
根据我的日志,我的空闲资源正在工作。但是查看日志的时间戳,异常发生在空闲资源空闲大约 5 秒后。
在资源闲置和尝试查找视图之间似乎存在延迟。
其他可能相关的细节:
- minSdk: 20
- 编译 & targetSdk: 25
- 构建工具:25.0.2
- 支持库:25.1.1
- 浓缩咖啡芯:2.2.2
- gradle 插件 2.3.0-beta3
除了夸大我的小吃店的显示时间之外,我如何修复此测试以使其不至于不稳定?
【问题讨论】:
标签: android android-support-library android-espresso android-snackbar