Espresso - 如何在没有断言/查看交互的情况下等待空闲?

Zak*_*rdi 6 android android-espresso

我想简单地阻塞检测(测试)线程,直到 Espresso 空闲。

fun test(){
    // do some stuff
    Espresso.waitForIdle()
    // do some more stuff once Espresso reports that the application is idle
}
Run Code Online (Sandbox Code Playgroud)

做到这一点的最佳方法是什么?

注:Espresso.waitForIdle()是我编的方法

che*_*ork 6

您可以使用InstrumentationRegistry.getInstrumentation().waitForIdleSync(). https://developer.android.com/reference/android/app/Instrumentation.html#waitForIdleSync()

还有Espresso.onIdle(),但文档警告Only call this method for tests that do not interact with any UI elements, but require Espresso's main thread synchronisation! https://developer.android.com/reference/android/support/test/espresso/Espresso.html#onIdle()

  • 还有`Espresso.onIdle()` 似乎可以做你想做的事。https://developer.android.com/reference/android/support/test/espresso/Espresso.html#onIdle() (2认同)