@@ -784,7 +784,7 @@ In `src/contributors/Contributors.kt`, check the implementation of the _CONCURRE
784784 argument, you can call this function in any context: with a `Default` dispatcher, with
785785 the main UI thread, or with a custom dispatcher.
786786 * As you' ll see later, when calling `loadContributorsConcurrent()` from tests, you can call it in the context
787- with `TestCoroutineDispatcher `, which simplifies testing. That makes this solution much more flexible.
787+ with `TestDispatcher `, which simplifies testing. That makes this solution much more flexible.
788788
7897892 . To specify the dispatcher on the caller side, apply the following change to the project while
790790 letting `loadContributorsConcurrent` start coroutines in the inherited context:
@@ -1390,14 +1390,14 @@ total running time drastically decreases:
13901390
13911391! [Comparison for total running time](time- comparison.png){width= 700 }
13921392
1393- To use virtual time, replace the `runBlocking` invocation with a `runBlockingTest `. `runBlockingTest ` takes an
1394- extension lambda to `TestCoroutineScope ` as an argument.
1393+ To use virtual time, replace the `runBlocking` invocation with a `runTest `. `runTest ` takes an
1394+ extension lambda to `TestScope ` as an argument.
13951395When you call `delay` in a `suspend ` function inside this special scope, `delay` will increase the virtual time instead
13961396of delaying in real time:
13971397
13981398```kotlin
13991399@Test
1400- fun testDelayInSuspend () = runBlockingTest {
1400+ fun testDelayInSuspend () = runTest {
14011401 val realStartTime = System .currentTimeMillis()
14021402 val virtualStartTime = currentTime
14031403
@@ -1412,18 +1412,18 @@ suspend fun foo() {
14121412}
14131413```
14141414
1415- You can check the current virtual time using the `currentTime` property of `TestCoroutineScope `.
1415+ You can check the current virtual time using the `currentTime` property of `TestScope `.
14161416
14171417The actual running time in this example is several milliseconds, whereas virtual time equals the delay argument, which
14181418is 1000 milliseconds.
14191419
14201420To get the full effect of " virtual" `delay` in child coroutines,
1421- start all of the child coroutines with `TestCoroutineDispatcher `. Otherwise , it won' t work. This dispatcher is
1422- automatically inherited from the other `TestCoroutineScope `, unless you provide a different dispatcher:
1421+ start all of the child coroutines with `TestDispatcher `. Otherwise , it won' t work. This dispatcher is
1422+ automatically inherited from the other `TestScope `, unless you provide a different dispatcher:
14231423
14241424```kotlin
14251425@Test
1426- fun testDelayInLaunch() = runBlockingTest {
1426+ fun testDelayInLaunch() = runTest {
14271427 val realStartTime = System.currentTimeMillis()
14281428 val virtualStartTime = currentTime
14291429
@@ -1481,11 +1481,11 @@ Compare the total running times before and after applying your refactoring.
14811481
14821482#### Tip for task 8 {initial-collapse-state="collapsed"}
14831483
1484- 1. Replace the `runBlocking` invocation with `runBlockingTest `, and replace `System.currentTimeMillis()` with `currentTime`:
1484+ 1. Replace the `runBlocking` invocation with `runTest `, and replace `System.currentTimeMillis()` with `currentTime`:
14851485
14861486 ```kotlin
14871487 @Test
1488- fun test() = runBlockingTest {
1488+ fun test() = runTest {
14891489 val startTime = currentTime
14901490 // action
14911491 val totalTime = currentTime - startTime
@@ -1501,7 +1501,7 @@ Compare the total running times before and after applying your refactoring.
15011501Here are the solutions for the concurrent and channels cases:
15021502
15031503```kotlin
1504- fun testConcurrent () = runBlockingTest {
1504+ fun testConcurrent () = runTest {
15051505 val startTime = currentTime
15061506 val result = loadContributorsConcurrent(MockGithubService , testRequestData)
15071507 Assert .assertEquals(" Wrong result for 'loadContributorsConcurrent'" , expectedConcurrentResults.users, result)
@@ -1519,7 +1519,7 @@ First, check that the results are available exactly at the expected virtual time
15191519themselves:
15201520
15211521```kotlin
1522- fun testChannels () = runBlockingTest {
1522+ fun testChannels () = runTest {
15231523 val startTime = currentTime
15241524 var index = 0
15251525 loadContributorsChannels(MockGithubService , testRequestData) { users, _ ->
0 commit comments