Created
April 14, 2018 11:52
-
-
Save tomkoptel/6a7301ac01183c8853ea278de6780c0e to your computer and use it in GitHub Desktop.
Alternative way to make Espresso aware of the coroutines execution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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