Android instrumentation test doesn't run to end when using Room @Transaction function

前端 未结 2 827
有刺的猬
有刺的猬 2020-12-19 12:28

I\'m testing with AS 3.4.1 and Emulator running Android 9.

The following test won\'t run, when I use a Room Dao Function annotated with @Transaction in

2条回答
  •  时光取名叫无心
    2020-12-19 12:49

    I faced the same issue and the problem was because of the InstantTaskExecutorRule, if you remove the below block of code the @Transaction should work fine with the suspend keyword

    @Rule
    @JvmField
    val instantTaskExecutorRule = InstantTaskExecutorRule()
    

    It seems that this rule blocks the RoomDatabase from acquiring the transaction thread. In RoomDatabase.kt execution gets blocked in the below function:

    private suspend fun Executor.acquireTransactionThread(controlJob: Job): ContinuationInterceptor
    

    Hope this helps!

提交回复
热议问题