Is your feature request related to a problem? Please describe.
Espresso UI tests that do depend on images loading, for instance before taking screenshot or asserting some bitmap computation.
Describe the solution you'd like
In order to signal ongoing image loading to Espresso, Coil can expose an IdlingResource.
Additional context
Glide and Picasso doesn't provide an out-of-the-box solution but workarounds exist:
https://lcdsmao.dev/synchronize-glide-loading-in-test-with-idlingresource/
https://gist.github.com/sebaslogen/0b2fdea3f322c730e04b0af7285fcd28
Wouldn't that be solved by wrapping your CoroutineDispatcher around an IdlingThreadPoolExecutor?
Something like:
private val idlingThreadPool = IdlingThreadPoolExecutor(
"coroutinesDispatchersThreadPool",
Runtime.getRuntime().availableProcessors(),
Runtime.getRuntime().availableProcessors(),
0L,
TimeUnit.MILLISECONDS,
LinkedBlockingQueue(),
Executors.defaultThreadFactory()
)
And when you build your ImageLoader instance
override fun newImageLoader(): ImageLoader =
ImageLoader.Builder(context)
.dispatcher(idlingThreadPool.asCoroutineDispatcher())
.build()
Indeed, will try that. Didn't know about IdlingThreadPoolExecutor, it seems to solve the problem in an even better way.
Thanks, issue to be closed.
Most helpful comment
Wouldn't that be solved by wrapping your
CoroutineDispatcheraround anIdlingThreadPoolExecutor?Something like:
And when you build your
ImageLoaderinstance