2022年6月22日 星期三

Android coroutine 1.6.0 遷移與測試

coroutine 1.6.0 在測試 api 上有些變化

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


沒有留言:

張貼留言