runBlocking -> runTest
TestCoroutineDispatcher -> 分成 StandardTestDispatcher 與 UnconfinedTestDispatcher
MainDispatcherRule 會變成這樣
// Reusable JUnit4 TestRule to override the Main dispatcher
class MainDispatcherRule(
val testDispatcher: TestDispatcher = UnconfinedTestDispatcher(),
) : TestWatcher() {
override fun starting(description: Description) {
Dispatchers.setMain(testDispatcher)
}
override fun finished(description: Description) {
Dispatchers.resetMain()
}
}
from: https://developer.android.com/kotlin/coroutines/test
沒有留言:
張貼留言