File tree Expand file tree Collapse file tree
app/src/test/java/com/lukaslechner/coroutineusecasesonandroid/playground/testing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ import kotlinx.coroutines.CoroutineScope
44import kotlinx.coroutines.delay
55import kotlinx.coroutines.launch
66import kotlinx.coroutines.test.advanceTimeBy
7+ import kotlinx.coroutines.test.advanceUntilIdle
78import kotlinx.coroutines.test.currentTime
9+ import kotlinx.coroutines.test.runCurrent
810import kotlinx.coroutines.test.runTest
911import org.junit.Test
1012
@@ -19,8 +21,10 @@ class SystemUnderTest {
1921
2022fun 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
You can’t perform that action at this time.
0 commit comments