使用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
,但它也不起作用。怎么了 ?
最佳答案
您在下面的代码安全范围内错过了return true;
:
if (mIdle) {
if (mResourceCallback != null) {
mResourceCallback.onTransitionToIdle();
return true; // this one is missed
}
}
关于android - IdlingResources无法正常使用Espresso Android,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43153497/