1)所有正在测试的设备/模拟器都禁用了动画。片状安卓咖啡测试 - 小吃店
2)我有一个@BeforeClass构建我的凭证对象。
3)我有一个IntenServiceIdlingResource和一个EventBusIdlingResource,注册在@Before中。
4)当点击登录按钮时,IntentService会关闭。在这种情况下,服务器(模拟服务器)返回500错误。该信息通过绿色机器人的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] FAILED android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: a string starting with "Server Error: 500"
根据我的记录,我的空转资源工作。但查看日志的时间戳,异常发生在空闲资源闲置约5秒后。
似乎资源闲置时以及尝试查找视图之间存在延迟。
其他可能的相关细节:
- minSdk:20
- 编译& targetSdk:25
- 编译工具:25.0.2
- 支持库:25.1.1
- 咖啡核:2.2.2
- gradle插件2.3.0-beta3
我该如何修复这个测试,使它不是片状,除了膨胀多长时间我的小吃店显示?
谢谢。 Espresso对IdlingResource的依赖正在推动着我的香蕉。没有很好的理由将测试框架代码投入到我的类中,而这正是应该如何正确完成的。 我仍然不能相信Espresso已经没有这样的东西了! –