Skip to content

Instantly share code, notes, and snippets.

@tomkoptel
Created April 14, 2018 11:52
Show Gist options
  • Save tomkoptel/6a7301ac01183c8853ea278de6780c0e to your computer and use it in GitHub Desktop.
Save tomkoptel/6a7301ac01183c8853ea278de6780c0e to your computer and use it in GitHub Desktop.
Alternative way to make Espresso aware of the coroutines execution.
import android.support.test.espresso.IdlingResource
import co.metalab.asyncawait.onIdleCoroutines
import co.metalab.asyncawait.onRunningCoroutine
class AsyncIdlingResource : IdlingResource {
private var areCoroutinesIdle = true
private var callback: IdlingResource.ResourceCallback? = null
override fun getName(): String = "AsyncIdlingResource"
override fun isIdleNow(): Boolean = areCoroutinesIdle
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
this.callback = callback
onRunningCoroutine = {
areCoroutinesIdle = false
callback?.onTransitionToIdle()
}
onIdleCoroutines = {
areCoroutinesIdle = true
callback?.onTransitionToIdle()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment