@@ -476,6 +476,62 @@ class TestScopeTest {
476
476
}
477
477
}
478
478
479
+ /* *
480
+ * Tests that the [TestScope] exception reporting mechanism will report the exceptions that happen between
481
+ * different tests.
482
+ *
483
+ * This test must be ran manually, because such exceptions still go through the global exception handler
484
+ * (as there's no guarantee that another test will happen), and the global exception handler will
485
+ * log the exceptions or, on Native, crash the test suite.
486
+ */
487
+ @Test
488
+ @Ignore
489
+ fun testReportingStrayUncaughtExceptionsBetweenTests () {
490
+ val thrown = TestException (" x" )
491
+ testResultChain({
492
+ // register a handler for uncaught exceptions
493
+ runTest { }
494
+ }, {
495
+ GlobalScope .launch(start = CoroutineStart .UNDISPATCHED ) {
496
+ throw thrown
497
+ }
498
+ runTest {
499
+ fail(" unreached" )
500
+ }
501
+ }, {
502
+ // this `runTest` will not report the exception
503
+ runTest {
504
+ when (val exception = it.exceptionOrNull()) {
505
+ is UncaughtExceptionsBeforeTest -> {
506
+ assertEquals(1 , exception.suppressedExceptions.size)
507
+ assertSame(exception.suppressedExceptions[0 ], thrown)
508
+ }
509
+ else -> fail(" unexpected exception: $exception " )
510
+ }
511
+ }
512
+ })
513
+ }
514
+
515
+ /* *
516
+ * Tests that the uncaught exceptions that happen during the test are reported.
517
+ */
518
+ @Test
519
+ fun testReportingStrayUncaughtExceptionsDuringTest (): TestResult {
520
+ val thrown = TestException (" x" )
521
+ return testResultChain({ _ ->
522
+ runTest {
523
+ val job = launch(Dispatchers .Default + NonCancellable ) {
524
+ throw thrown
525
+ }
526
+ job.join()
527
+ }
528
+ }, {
529
+ runTest {
530
+ assertEquals(thrown, it.exceptionOrNull())
531
+ }
532
+ })
533
+ }
534
+
479
535
companion object {
480
536
internal val invalidContexts = listOf (
481
537
Dispatchers .Default , // not a [TestDispatcher]
0 commit comments