问题: 我在运行Espresso测试时遇到问题,在登录按钮上调用perform(click())方法后,测试继续运行但是直到45秒后才会继续运行并且测试自动失败.同时,登录正常进行.
上下文:我有一个带有两个片段的Activity,右边的片段处理用户名和密码EditTexts以及登录按钮.这个片段使用ViewAnimator和两个LinearLayouts作为子视图构建,第一个LinearLayout具有前面提到的元素,第二个具有其他东西.
这是在单击登录按钮时UI上发生的情况:
@Override
public void setUILoggingIn() {
spinnerLogin.setVisibility(View.VISIBLE);
loginButton.setEnabled(false);
loginButton.setText(R.string.logging_in);
usernameText.setEnabled(false);
passwordText.setEnabled(false);
}
Run Code Online (Sandbox Code Playgroud)
在使用服务器进行身份验证后,这就是我处理UI的方式:
@Override
public void setUIAuthorized() {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
viewAnimator.showNext();
// elements on the first child of the ViewAnimator
loginButton.setEnabled(true);
spinnerLogin.setVisibility(View.GONE);
// elements on the second child of the ViewAnimator
sendMessageButton.setEnabled(true);
chatInputText.setEnabled(true);
}
});
}
Run Code Online (Sandbox Code Playgroud)
浓咖啡测试
ViewInteraction loginButton2 = onView(withId(R.id.login_button));
loginButton2.perform(click()); // Test gets stuck here.
loginButton2.check(doesNotExist()); // Never reached.
Run Code Online (Sandbox Code Playgroud)
有没有人知道在这种情况下成功测试?只需检测ViewAnimator何时更改,但测试卡在点击上就足够了.
另外:这不是测试的开始,在之前显示的代码之前,我运行此测试并且它像梦一样工作:
ViewInteraction loginButton = onView(withId(R.id.login_button));
/** …Run Code Online (Sandbox Code Playgroud) testing android android-fragments viewanimator android-espresso
我尝试按照这些说明进行操作,因此我的 build.gradle(应用程序)的相关部分如下所示:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://jitpack.io' }
}
compile 'com.github.qiugang:EditTag:v1.2.3'
Run Code Online (Sandbox Code Playgroud)
但 Android Studio 仍然显示此错误消息:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
> Could not find com.github.qiugang:EditTag:v1.2.3.
Required by:
myapp-yeah:app:unspecified
Run Code Online (Sandbox Code Playgroud)