How to unit test suspend functions like RoomDatabase.withTransaction?
mgolokhov opened this issue · 0 comments
How to write proper coroutine dispatchers:
https://craigrussell.io/2019/11/unit-testing-coroutine-suspend-functions-using-testcoroutinedispatcher/
Even with dispatchers, a test fails with error:
java.lang.IllegalStateException: This job has not completed yet
Initial attempt to mock suspend functions:
mockito/mockito#1032
https://github.com/mockito/mockito/blob/885e69420baa2a382f4394b85dc84cb6fe17fff6/subprojects/kotlinTest/src/test/kotlin/org/mockito/kotlin/SuspendTest.kt
About RoomDatabase.withTransaction
:
https://medium.com/androiddevelopers/threading-models-in-coroutines-and-android-sqlite-api-6cab11f7eb90
https://medium.com/androiddevelopers/room-coroutines-422b786dc4c5
Hacks with library Mockk:
https://stackoverflow.com/questions/56500576/how-to-mock-android-room-withtransaction-method-with-mockk
https://proandroiddev.com/how-to-unit-test-room-runintransaction-3bac366e13f7