diff --git a/app/src/test/java/com/androiddevs/shoppinglisttestingyt/MainCoroutineRule.kt b/app/src/test/java/com/androiddevs/shoppinglisttestingyt/MainCoroutineRule.kt index f98629d..38a4f5e 100644 --- a/app/src/test/java/com/androiddevs/shoppinglisttestingyt/MainCoroutineRule.kt +++ b/app/src/test/java/com/androiddevs/shoppinglisttestingyt/MainCoroutineRule.kt @@ -3,26 +3,24 @@ package com.androiddevs.shoppinglisttestingyt import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.TestCoroutineDispatcher -import kotlinx.coroutines.test.TestCoroutineScope +import kotlinx.coroutines.test.UnconfinedTestDispatcher import kotlinx.coroutines.test.resetMain import kotlinx.coroutines.test.setMain import org.junit.rules.TestWatcher import org.junit.runner.Description -@ExperimentalCoroutinesApi -class MainCoroutineRule( - private val dispatcher: CoroutineDispatcher = TestCoroutineDispatcher() -) : TestWatcher(), TestCoroutineScope by TestCoroutineScope(dispatcher) { +@OptIn(ExperimentalCoroutinesApi::class) +class MainCoroutineRule constructor( + private val dispatcher: CoroutineDispatcher = UnconfinedTestDispatcher() +) : TestWatcher() { - override fun starting(description: Description?) { + override fun starting(description: Description) { super.starting(description) Dispatchers.setMain(dispatcher) } - override fun finished(description: Description?) { + override fun finished(description: Description) { super.finished(description) - cleanupTestCoroutines() Dispatchers.resetMain() } -} \ No newline at end of file +}