Issue Description
After updating the Kotlin version from 1.7.10 to 1.9.10, multiple tests are failing, and the primary issue is indicated by the error message:
kotlinx.coroutines.test.UncaughtExceptionsBeforeTest: There were uncaught exceptions before the test started. Please avoid this, as such exceptions are also reported in a platform-dependent manner so that they are not lost.
kotlinx.coroutines.test.UncaughtExceptionsBeforeTest: There were uncaught exceptions before the test started. Please avoid this, as such exceptions are also reported in a platform-dependent manner so that they are not lost.
at app//kotlinx.coroutines.test.TestScopeImpl.enter(TestScope.kt:242)
at app//kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:307)
at app//kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
at app//kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:166)
at app//kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
at app//kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0$default(TestBuilders.kt:158)
at app//kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0$default(Unknown Source)
Below are the mocking lib versions
- Mockk version - 1.13.8
- Mockito version - 5.6.0
- org.jetbrains.kotlinx:kotlinx-coroutines-test - 1.7.3
To resolve this, we can write our own global uncaught exception handler and re throw the exception to JVM to handle it
Also to add the rule in the test class