@@ -4,7 +4,7 @@ In version 1.6.0, the API of the test module changed significantly.
44This is a guide for gradually adapting the existing test code to the new API.
55This guide is written step-by-step; the idea is to separate the migration into several sets of small changes.
66
7- ## Remove custom ` UncaughtExceptionCaptor ` , ` DelayController ` , and ` TestCoroutineScope ` implementations
7+ ## Remove custom UncaughtExceptionCaptor, DelayController, and TestCoroutineScope implementations
88
99We couldn't find any code that defined new implementations of these interfaces, so they are deprecated. It's likely that
1010you don't need to do anything for this section.
@@ -61,7 +61,7 @@ So, there could be two reasons for defining a custom implementation:
6161* Using without ` runBlockingTest ` . In this case, you don't even need to implement ` TestCoroutineScope ` : nothing else
6262 accepts a ` TestCoroutineScope ` specifically as an argument.
6363
64- ## Remove usages of ` TestCoroutineExceptionHandler ` and ` TestCoroutineScope.uncaughtExceptions `
64+ ## Remove usages of TestCoroutineExceptionHandler and TestCoroutineScope.uncaughtExceptions
6565
6666It is already illegal to use a ` TestCoroutineScope ` without performing ` cleanupTestCoroutines ` , so the valid uses of
6767` TestCoroutineExceptionHandler ` include:
@@ -93,13 +93,13 @@ fun testFoo() = runTest {
9393}
9494```
9595
96- ## Auto-replace ` TestCoroutineScope ` constructor function with ` createTestCoroutineScope `
96+ ## Auto-replace TestCoroutineScope constructor function with createTestCoroutineScope
9797
9898This should not break anything, as ` TestCoroutineScope ` is now defined in terms of ` createTestCoroutineScope ` .
9999If it does break something, it means that you already supplied a ` TestCoroutineScheduler ` to some scope; in this case,
100100also pass this scheduler as the argument to the dispatcher.
101101
102- ## Replace usages of ` pauseDispatcher ` and ` resumeDispatcher ` with a ` StandardTestDispatcher `
102+ ## Replace usages of pauseDispatcher and resumeDispatcher with a StandardTestDispatcher
103103
104104* In places where ` pauseDispatcher ` in its block form is called, replace it with a call to
105105 ` withContext(StandardTestDispatcher(testScheduler)) `
@@ -120,7 +120,7 @@ also pass this scheduler as the argument to the dispatcher.
120120 ` StandardTestDispatcher ` (where dispatches are needed) and ` UnconfinedTestDispatcher ` (where it isn't important where
121121 execution happens).
122122
123- ## Replace ` advanceTimeBy(n) ` with ` advanceTimeBy(n); runCurrent() `
123+ ## Replace advanceTimeBy(n) with advanceTimeBy(n); runCurrent()
124124
125125For ` TestCoroutineScope ` and ` DelayController ` , the ` advanceTimeBy ` method is deprecated.
126126It is not deprecated for ` TestCoroutineScheduler ` and ` TestScope ` , but has a different meaning: it does not run the
@@ -131,7 +131,7 @@ There is an automatic replacement for this deprecation, which produces correct b
131131Alternatively, you can wait until replacing ` TestCoroutineScope ` with ` TestScope ` : it's possible that you will not
132132encounter this edge case.
133133
134- ## Replace ` runBlockingTest ` with ` runTest(UnconfinedTestDispatcher()) `
134+ ## Replace runBlockingTest with runTest(UnconfinedTestDispatcher())
135135
136136This is a major change, affecting many things, and can be done in parallel with replacing ` TestCoroutineScope ` with
137137` TestScope ` .
@@ -329,7 +329,7 @@ There is a `runTestWithLegacyScope` method that allows migrating from `runBlocki
329329from ` TestCoroutineScope ` to ` TestScope ` , if exactly the ` TestCoroutineScope ` needs to be passed somewhere else and
330330` TestScope ` will not suffice.
331331
332- ## Replace ` TestCoroutineScope.cleanupTestCoroutines ` with ` runTest `
332+ ## Replace TestCoroutineScope.cleanupTestCoroutines with runTest
333333
334334Likely can be done together with the next step.
335335
@@ -363,7 +363,7 @@ fun runTestAndCleanup(body: TestScope.() -> Unit) = runTest {
363363}
364364```
365365
366- ## Replace ` runBlockingTest ` with ` runBlockingTestOnTestScope ` , ` createTestCoroutineScope ` with ` TestScope `
366+ ## Replace runBlockingTest with runBlockingTestOnTestScope, createTestCoroutineScope with TestScope
367367
368368Also, replace ` runTestWithLegacyScope ` with just ` runTest ` .
369369All of this can be done in parallel with replacing ` runBlockingTest ` with ` runTest ` .
@@ -379,13 +379,13 @@ handle cancelled tasks differently: if there are *cancelled* jobs pending at the
379379Of all the methods supported by ` TestCoroutineScope ` , only ` cleanupTestCoroutines ` is not provided on ` TestScope ` ,
380380and its usages should have been removed during the previous step.
381381
382- ## Replace ` runBlocking ` with ` runTest `
382+ ## Replace runBlocking with runTest
383383
384384Now that ` runTest ` works properly with asynchronous completions, ` runBlocking ` is only occasionally useful.
385385As is, most uses of ` runBlocking ` in tests come from the need to interact with dispatchers that execute on other
386386threads, like ` Dispatchers.IO ` or ` Dispatchers.Default ` .
387387
388- ## Replace ` TestCoroutineDispatcher ` with ` UnconfinedTestDispatcher ` and ` StandardTestDispatcher `
388+ ## Replace TestCoroutineDispatcher with UnconfinedTestDispatcher and StandardTestDispatcher
389389
390390` TestCoroutineDispatcher ` is a dispatcher with two modes:
391391* ("unpaused") Almost (but not quite) unconfined, with the ability to eagerly enter ` launch ` and ` async ` blocks.
0 commit comments