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 秒。
资源空闲和尝试查找视图之间似乎存在延迟。
其他可能相关的细节:
- 最小SDK:20
- 编译和目标 SDK:25
- 构建工具:25.0.2
- 支持库:25.1.1
- 浓缩咖啡核心:2.2.2
- gradle插件2.3.0-beta3
除了增加小吃栏的显示时间之外,我该如何修复此测试,使其不不稳定?