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

前端 未结 2 829
有刺的猬
有刺的猬 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:57

    You can use setTransactionExecutor to run transaction in another thread

    return Room
           .inMemoryDatabaseBuilder(context, MyRoomDatabase::class.java)
           .setTransactionExecutor(Executors.newSingleThreadExecutor())
           .build()
    

    then while testing use runBlocking instead of runBlockingTest

    @Test
    fun moveItem() = runBlocking {
        transactionFunction()
    }
    

提交回复
热议问题