Android: How to use IdlingResource to wait for background tasks (Espresso)

I would like to ask for help about what I could not implement last week. I did some espresso tests when I discovered a serious problem.

Sometimes my tests were successful, but not always. The problem was that my application has several asynchronous tasks that I need to wait before checking the testing conditions. Usually Espresso just waits for tasks with main threads.

I use Executors to create new threads, something like this:

executor = Executors.newFixedThreadPool(MAX_THREADS);

And to check if I'm idle, I use this:

boolean isItIdle = executor.isTerminated() || executor.isShutdown();

Obviously, this solution does not work. Any help would be appreciated, thanks in advance.

+4
source share
1 answer

, .: (

, , Executor . , :

executor.shutdown();
boolean isItIdle = executor.isTerminated();

executor.shutdown() executor.isTerminated(). , shutdown (executor.isShutdown()), .

, -!;)

0

All Articles