我正在使用Junit4和Espresso进行测试.我正面临一个与espresso测试相关的奇怪问题 - 当我调用onView时,有时一切都按照它应该执行,但有时候我的测试会冻结,60秒后我得到类似这样的东西"android.support.test.espresso.AppNotIdleException:Looped超过60秒的63次迭代.以下空闲条件失败ASYNC_TASKS_HAVE_IDLED"例如:
onView(withId(R.id.zone_button_continue)).perform(click());
onView(withId(R.id.loginButton)).check(matches(isDisplayed()));
onView(withId(R.id.number)).check(matches(isDisplayed()));
onView(withId(R.id.password)).check(matches(isDisplayed()));
onView(withId(R.id.number)).perform(typeText(phoneNumber));
onView(withId(R.id.password)).perform(typeText(password));
onView(withId(R.id.loginButton)).perform(click());
Run Code Online (Sandbox Code Playgroud)
一切都得到了正确执行,除了最后一行 - 由于某种原因,它找不到loginButton,但它有100%的百分比.我可以
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.findViewById(R.id.loginButton).performClick();
}
});
Run Code Online (Sandbox Code Playgroud)
这很有效.在我的大多数活动中我都遇到过类似的问题 - 有时onView工作有时候没有.
什么可能导致这种不一致?我一直在与这个问题作斗争,这让我的测试非常令人沮丧和困难.我的结论到目前为止我的gradle依赖项出了问题,或者我的应用程序中存在某种阻止espresso正常工作的错误.但奇怪的是,在上面的例子中,onView的所有内容都在工作,除了最后一行,一切都发生在一个活动中,这让我怀疑这个bug是在我的应用程序中.这是我的gradle依赖项:
compile files('src/main/libs/guice-3.0-no_aop.jar')
compile files('src/main/libs/javax.inject-1.jar')
compile files('src/main/libs/roboguice-2.0.jar')
compile files('src/main/libs/junit-4.11.jar')
compile files('src/main/libs/hamcrest-core-1.3.jar')
compile files('src/main/libs/GeoLib.jar')
compile files('src/main/libs/GeoPolygons.jar')
compile files('src/main/libs/universal-image-loader-1.9.4.jar')
compile files('src/main/libs/javax.annotation-3.2-b06-sources.jar')
compile ('uk.co.chrisjenx:calligraphy:2.1.0'){
exclude group:'com.android.support'
}
compile 'com.squareup:otto:1.3.5'
compile ('com.google.android.gms:play-services:6.5.87'){
exclude group:'com.android.support'
}
compile 'com.android.support:support-annotations:22.2.1'
compile ('com.android.support:appcompat-v7:22.2.0'){
exclude group:'com.android.support'
}
compile ('com.android.support:support-v4:22.2.0'){
exclude group:'com.android.support', module:'support-annotations'
}
compile ('com.android.support:palette-v7:22.2.0'){
exclude group:'com.android.support'
}
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.nineoldandroids:library:2.4.0' …Run Code Online (Sandbox Code Playgroud)