You didn't really provide a question here, so I assume the question is about why this setup is not working as expected.
There are (at least) two reasons:
The assert
assertTrue(getActivity().isDidThreadReturn());
intestThreadRetrieval()
does not wait at all for IdlingResources to be finished. OnlyViewInteraction.check()
andViewInteraction.perform()
are aware of those and will check IdlingResources before trying to apply theViewAssertion
orViewAction
.Even if the commented out line after the
assertTrue()
is applied instead, it would not work, because the instrumentation thread is independent and doesn't wait for the new thread created ingetReps()
to start, so the check of IdlingResources can and will happen before theCountingIdlingResource
is incremented.
If, for whatever reason, you really don't want to use an AsyncTask, you still can profit from Espresso watching the AsynTask thread pool by using its executor. So instead of starting a separate thread, just submit the Runnable to the AsyncTask.THREAD_POOL_EXECUTOR
.