使用Espresso
进行测试时,我遇到了闲置资源的问题。
它不起作用。它只被调用两次,即使返回false
也是如此。
public class MyIdlingResource implements IdlingResource {
private boolean mIdle;
private ResourceCallback mResourceCallback;
public MyIdlingResource () {
this.mIdle = false;
this.mResourceCallback = null;
}
@Override
public final String getName() {
return MyIdlingResource .class.getSimpleName();
}
@Override
public final boolean isIdleNow() {
ArrayList<View> views = doStuff();
mIdle = views != null && !views.isEmpty();
if (mIdle) {
if (mResourceCallback != null) {
mResourceCallback.onTransitionToIdle();
}
}
return false;
}
@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
mResourceCallback = resourceCallback;
}
}
所以在这种情况下我会一直返回false
,但它也不起作用。
有什么问题?
答案 0 :(得分:1)
你错过了return true;
以下代码的和平:
if (mIdle) {
if (mResourceCallback != null) {
mResourceCallback.onTransitionToIdle();
return true; // this one is missed
}
}