I have the following Presenter class and test setu...
# coroutines
l
I have the following Presenter class and test setup for it:
Copy code
class Presenter(
    val api: Api,
    coroutineContext: CoroutineContext
) {

    val coroutineScope = CoroutineScope(coroutineContext)

    fun onAttachView(view View) {
        coroutineScope.launch {
            api.getDetail()
        }
    }
}
Test:
Copy code
import io.mockk.*

class PresenterTest {

    val testCoroutineScope = TestCoroutineScope()

    val presenter = Presenter(
        api = mockk(),
        coroutineContext = testCoroutineScope.coroutineContext
    )
    val view = mockk()

    @AfterEach
    fun tearDown() {
        testCoroutineScope.cleanupTestCoroutines()
    }

    @Test
    fun `when view attached then call API`() {
        presenter.test().attachView(view)

        coVerify { api.getData() }
    }
}
How do I migrate it to coroutine-test 1.6.0?
Is it enough to just replace
TestCoroutineScope()
with
TestScope()
and then I can remove the whole
tearDown()
function? Or do I need to also wrap each test into
runTest {}
now?
How is
runTest {}
connected to
TestScope()
? Does it automatically use the instance I created in my test class or do I need to pass my
TestScope
instance to the
runTest
method somehow?
Ok, it looks like the following test setup is working correctly in this case:
Copy code
val testScope = TestScope(UnconfinedTestDispatcher())

val testPresenter = Presenter(
        coroutineContext = testScope.coroutineContext
    )
}

@Test
fun `some test`() = testScope.runTest {
    // test body
}
The 
UnconfinedTestDispatcher
 is apparently important, as with 
StandardTestDispatcher
 the coroutines you launch inside your presenter won't be executed (for whatever reason).