Skip to content

Commit d48eeb4

Browse files
committed
add dynamic tests
1 parent de6c87c commit d48eeb4

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

junit-jupiter-engine/src/test/kotlin/org/junit/jupiter/api/KotlinAssertionsTests.kt

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,44 @@ class KotlinAssertionsTests {
6262
}
6363

6464
@Test
65-
fun `assertThrows with coroutines`() = runBlocking<Unit> {
65+
fun `expected context exception testing`() = runBlocking<Unit> {
6666
assertThrows<AssertionError>("Should fail async") {
6767
suspend { fail("Should fail async") }()
6868
}
6969
}
7070

71-
@Test
72-
fun `assertDoesNotThrow with coroutines`() = runBlocking {
73-
val result = assertDoesNotThrow {
74-
suspend { "Result" }()
75-
}
76-
77-
assertEquals("Result", result)
78-
}
79-
8071
@TestFactory
8172
fun assertDoesNotThrow(): Stream<out DynamicNode> = Stream.of(
8273
dynamicContainer("succeeds when no exception thrown", Stream.of(
8374
dynamicTest("for no arguments variant") {
8475
val actual = assertDoesNotThrow { 1 }
8576
assertEquals(1, actual)
8677
},
78+
dynamicTest("for no arguments variant (suspended)") {
79+
runBlocking {
80+
val actual = assertDoesNotThrow { suspend { 1 }() }
81+
assertEquals(1, actual)
82+
}
83+
},
8784
dynamicTest("for message variant") {
8885
val actual = assertDoesNotThrow("message") { 2 }
8986
assertEquals(2, actual)
9087
},
88+
dynamicTest("for message variant (suspended)") {
89+
runBlocking {
90+
val actual = assertDoesNotThrow("message") { suspend { 2 }() }
91+
assertEquals(2, actual)
92+
}
93+
},
9194
dynamicTest("for message supplier variant") {
9295
val actual = assertDoesNotThrow({ "message" }) { 3 }
9396
assertEquals(3, actual)
97+
},
98+
dynamicTest("for message supplier variant (suspended)") {
99+
runBlocking {
100+
val actual = assertDoesNotThrow({ "message" }) { suspend { 3 }() }
101+
assertEquals(3, actual)
102+
}
94103
}
95104
)),
96105
dynamicContainer("fails when an exception is thrown", Stream.of(
@@ -103,6 +112,19 @@ class KotlinAssertionsTests {
103112
assertMessageEquals(exception,
104113
"Unexpected exception thrown: org.opentest4j.AssertionFailedError: fail")
105114
},
115+
dynamicTest("for no arguments variant (suspended)") {
116+
runBlocking {
117+
val exception = assertThrows<AssertionError> {
118+
assertDoesNotThrow {
119+
suspend { fail("fail") }()
120+
}
121+
}
122+
assertMessageEquals(
123+
exception,
124+
"Unexpected exception thrown: org.opentest4j.AssertionFailedError: fail"
125+
)
126+
}
127+
},
106128
dynamicTest("for message variant") {
107129
val exception = assertThrows<AssertionError> {
108130
assertDoesNotThrow("Does not throw") {
@@ -112,6 +134,19 @@ class KotlinAssertionsTests {
112134
assertMessageEquals(exception,
113135
"Does not throw ==> Unexpected exception thrown: org.opentest4j.AssertionFailedError: fail")
114136
},
137+
dynamicTest("for message variant (suspended)") {
138+
runBlocking {
139+
val exception = assertThrows<AssertionError> {
140+
assertDoesNotThrow("Does not throw") {
141+
suspend { fail("fail") }()
142+
}
143+
}
144+
assertMessageEquals(
145+
exception,
146+
"Does not throw ==> Unexpected exception thrown: org.opentest4j.AssertionFailedError: fail"
147+
)
148+
}
149+
},
115150
dynamicTest("for message supplier variant") {
116151
val exception = assertThrows<AssertionError> {
117152
assertDoesNotThrow({ "Does not throw" }) {
@@ -120,6 +155,19 @@ class KotlinAssertionsTests {
120155
}
121156
assertMessageEquals(exception,
122157
"Does not throw ==> Unexpected exception thrown: org.opentest4j.AssertionFailedError: fail")
158+
},
159+
dynamicTest("for message supplier variant (suspended)") {
160+
runBlocking {
161+
val exception = assertThrows<AssertionError> {
162+
assertDoesNotThrow({ "Does not throw" }) {
163+
suspend { fail("fail") }()
164+
}
165+
}
166+
assertMessageEquals(
167+
exception,
168+
"Does not throw ==> Unexpected exception thrown: org.opentest4j.AssertionFailedError: fail"
169+
)
170+
}
123171
}
124172
))
125173
)

0 commit comments

Comments
 (0)