File tree 1 file changed +34
-0
lines changed
kotlinx-coroutines-test/common/test
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -217,4 +217,38 @@ class RunTestTest {
217
217
}
218
218
})
219
219
220
+ /* * Tests that [runTest] completes its job. */
221
+ @Test
222
+ fun testCompletesOwnJob (): TestResult {
223
+ var handlerCalled = false
224
+ return testResultMap({
225
+ it()
226
+ assertTrue(handlerCalled)
227
+ }, {
228
+ runTest {
229
+ coroutineContext.job.invokeOnCompletion {
230
+ handlerCalled = true
231
+ }
232
+ }
233
+ })
234
+ }
235
+
236
+ /* * Tests that [runTest] doesn't complete the job that was passed to it as an argument. */
237
+ @Test
238
+ fun testDoesNotCompleteGivenJob (): TestResult {
239
+ var handlerCalled = false
240
+ val job = Job ()
241
+ job.invokeOnCompletion {
242
+ handlerCalled = true
243
+ }
244
+ return testResultMap({
245
+ it()
246
+ assertFalse(handlerCalled)
247
+ assertEquals(0 , job.children.filter { it.isActive }.count())
248
+ }, {
249
+ runTest(job) {
250
+ assertTrue(coroutineContext.job in job.children)
251
+ }
252
+ })
253
+ }
220
254
}
You can’t perform that action at this time.
0 commit comments