浓缩咖啡-如何在没有声明/视图交互的情况下等待空闲状态?

时间:2018-11-01 17:52:45

标签: android android-espresso

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

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

最好的方法是什么?

注意:Espresso.waitForIdle()是我设计的方法

1 个答案:

答案 0 :(得分:0)

您可以使用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()