我想简单地阻塞检测(测试)线程,直到Espresso空闲。
fun test(){
// do some stuff
Espresso.waitForIdle()
// do some more stuff once Espresso reports that the application is idle
}
最好的方法是什么?
注意:Espresso.waitForIdle()
是我设计的方法
答案 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()