File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
app/src/test/java/com/wzq/jd/compose/app Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 11package com.wzq.jd.compose.app
22
3+ import kotlinx.coroutines.SupervisorJob
4+ import kotlinx.coroutines.launch
5+ import kotlinx.coroutines.runBlocking
36import org.junit.Test
47
58import 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}
You can’t perform that action at this time.
0 commit comments