Skip to content

Commit 6bb4668

Browse files
Adjust 1_testing_coroutines.kt
1 parent 1cd20a8 commit 6bb4668

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

app/src/test/java/com/lukaslechner/coroutineusecasesonandroid/playground/testing/1_testing_coroutines.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import kotlinx.coroutines.CoroutineScope
44
import kotlinx.coroutines.delay
55
import kotlinx.coroutines.launch
66
import kotlinx.coroutines.test.advanceTimeBy
7+
import kotlinx.coroutines.test.advanceUntilIdle
78
import kotlinx.coroutines.test.currentTime
9+
import kotlinx.coroutines.test.runCurrent
810
import kotlinx.coroutines.test.runTest
911
import org.junit.Test
1012

@@ -19,8 +21,10 @@ class SystemUnderTest {
1921

2022
fun CoroutineScope.functionThatStartsNewCoroutine() {
2123
launch {
22-
delay(1000)
23-
println("Coroutine completed!")
24+
delay(500)
25+
println("Task A was executed")
26+
delay(500)
27+
println("Task B was executed")
2428
}
2529
}
2630

@@ -33,7 +37,11 @@ class TestClass {
3337
val virtualTimeStart = currentTime
3438

3539
functionThatStartsNewCoroutine()
36-
advanceTimeBy(1000)
40+
41+
// advanceTimeBy(500)
42+
// runCurrent()
43+
44+
advanceUntilIdle()
3745

3846
val realTimeDuration = System.currentTimeMillis() - realTimeStart
3947
val virtualTimeDuration = currentTime - virtualTimeStart

0 commit comments

Comments
 (0)