espresso test ignores IdlingResouce isIdle() returning false

By : Lanitka

There is an IdlingResource, e.g. like this

public class IRWatchlistNamesLoaded implements IdlingResource {

private final static String CLASSNAME = "IRWatchlistNamesLoaded";
private ResourceCallback callback;

public IRWatchlistNamesLoaded () {}

public String getName() {
    return getClass().getName();

public boolean isIdleNow() {
    if(LMaxApplication.watchlists.getNames() != null && LMaxApplication.watchlists.getNames().size() > 0) {
        CustomLog.print(CustomLog.UI_TEST, CLASSNAME, "isIdleNow = TRUE. size  = " + LMaxApplication.watchlists.getNames().size());
        return true;
    CustomLog.print(CustomLog.UI_TEST, CLASSNAME, "isIdleNow = FALSE. size  = " + LMaxApplication.watchlists.getNames().size());
    return false;

public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
    this.callback = resourceCallback;


And the usage is standard - when I need the resource I call

 watchlistLoadedIR = new IRWatchlistNamesLoaded();
 needToUnregisterWatchlistLoadedIR = true;

What I see in logs is that isIdle() returns false (1 or 2 times), my test keeps going and my resource is not loaded properly, so test fails. Also, need to notice that in some other tests this IdlingResource works and espresso really waits for the resource to be idle. The usage is absolutely the same. Please, maybe somebody has any idea why this could happen?

By : Lanitka


I don't know if this will help but there is a great way of setting up IdlingResources described here which might help solve your problem. I have a sneaking suspicion that it has to do with the fact that you are instantiating your class within the test, which I don't think is what you want to be doing, since you need to be using the IdlingResources from with an activity, using onView to perform action on different components which would then end up running the class in question.

By : MultiJ

This video can help you solving your question :)
By: admin