Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even After bumping kotlinx coroutine test dependency to 1.8.0 giving an UncaughtExceptionsBeforeTest. #4119

Open
harshal-msf opened this issue May 2, 2024 · 4 comments

Comments

@harshal-msf
Copy link

harshal-msf commented May 2, 2024

When running a testcase, it fails and in the stacktrace shows the following trace:

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 kotlinx.coroutines.test.TestScopeImpl.enter(TestScope.kt:239)
    at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:309)
    at kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
    at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0(TestBuilders.kt:168)
    at kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0(Unknown Source)
    at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0$default(TestBuilders.kt:160)
    at kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0$default(Unknown Source)

Observation:
When I correct a test that throws the "UncaughtExceptionsBeforeTest" exception, it passes, but then another test in a different class fails with the same exception. Fixing the new failing test causes another to fail, and this cycle continues.

Things which i have tried to solve this issue:

  1. Bump kotlinxCoroutinesTest version to 1.8.0

  2. Running failed tests which has runTest method inside try catch block to check all suppressed exception.

  3. Checked if any exception is thrown before and added that same exception in try catch block.

  4. Used Test dispatcher rule which make tests run on same coroutine.

Is there anything i'm missing, to solve this issue i checked all previous issues conversations and applied those fixes which mentioned in the conversation still getting this same issue.

@dkhalanskyjb
Copy link
Contributor

dkhalanskyjb commented May 3, 2024

The fix is what the exception says: don't throw any exceptions before runTest starts. Exceptions thrown before runTest begins are always considered to be errors.

@harshal-msf
Copy link
Author

Yes Exceptions is self-explanatory. However, when I implemented a try-catch block to check for suppressed exceptions, none were returned. Despite observing that suppressed exceptions are added in TestScope.enter(), none are being printed.
Not sure am i missing any step?

@dkhalanskyjb dkhalanskyjb added bug and removed question labels May 3, 2024
@dkhalanskyjb
Copy link
Contributor

Interesting. Do you observe suppressed exceptions if you add Thread.sleep(1000) just before runTest?

@harshal-msf
Copy link
Author

Need to check this i will check this and update accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants