Skip to content

Commit 42a140f

Browse files
committed
update
1 parent 3fa2d7d commit 42a140f

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

app/src/test/java/com/wzq/jd/compose/app/ExampleUnitTest.kt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.wzq.jd.compose.app
22

3+
import kotlinx.coroutines.SupervisorJob
4+
import kotlinx.coroutines.launch
5+
import kotlinx.coroutines.runBlocking
36
import org.junit.Test
47

58
import org.junit.Assert.*
@@ -14,4 +17,50 @@ class ExampleUnitTest {
1417
fun addition_isCorrect() {
1518
assertEquals(4, 2 + 2)
1619
}
20+
21+
@Test
22+
fun test() = runBlocking {
23+
24+
val supervisorJob = SupervisorJob()
25+
26+
val parentJob = launch(supervisorJob) {
27+
val childJob1 = launch {
28+
// 子协程1的操作
29+
println(1)
30+
}
31+
32+
val childJob2 = launch {
33+
// 子协程2的操作,可能会失败
34+
throw Exception("Child job 2 failed")
35+
}
36+
37+
val job3 = launch {
38+
println(3)
39+
}
40+
}
41+
42+
parentJob.join()
43+
44+
Unit
45+
}
46+
47+
48+
@Test
49+
fun goodTest() = runBlocking {
50+
val job = SupervisorJob()
51+
52+
launch(job) {
53+
println(1)
54+
}
55+
56+
launch(job) {
57+
throw Exception("job2")
58+
}
59+
60+
launch(job) {
61+
println(3)
62+
}
63+
64+
Unit
65+
}
1766
}

0 commit comments

Comments
 (0)