-
-
Notifications
You must be signed in to change notification settings - Fork 332
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
Bug: Mocking method that returns coroutine Job fails in android instrumentation test #237
Comments
Thanks |
@oleksiyp any update on this? I'm facing the same issue with MockK: |
Hi, not yet |
@oleksiyp It seems to be working with JUnit5, if that helps. |
I ended up not using the single expression function Kotlin feature and wrapped the
body in braces so that my function returned Unit.
…On Sat, Mar 2, 2019 at 1:08 PM Razil ***@***.***> wrote:
@oleksiyp <https://github.com/oleksiyp> It seems to be working with
JUnit5, if that helps.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#237 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ATMtNXgOetpwvQXYaTF-BpzS447NeyK-ks5vSkaFgaJpZM4aUTKg>
.
|
I can tell with 99% that this is an issue of incompatibility Kotlin bytecode with Java Reflection API. Next step is to raise Kotlin ticket and wait if it can be resolved |
I get the same error trying to mock Retrofit interfaces with methods that return Deferred. |
I have a similar problem where I'm trying to capture a coroutine context, and I get the following error:
The code is kinda big, but this is the relevant part: val coroutineSlot = slot<suspend CoroutineScope.() -> Unit>()
every { stuffHere(arg1, arg2, capture(coroutineSlot)) } returns jobMockk If you add something like
(So CoroutineContext instead of CoroutineId) Any tips for this? I am not able to Versions: |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as |
Any update about this issue! |
Update on this? |
Any update on this?
I'm getting: Caused by: java.lang.ClassCastException: class com.textnow.android.events.GenericEventTracker cannot be cast to class kotlinx.coroutines.CoroutineScope (com.textnow.android.events.GenericEventTracker and kotlinx.coroutines.CoroutineScope are in unnamed module of loader org.robolectric.internal.AndroidSandbox$SdkSandboxClassLoader @55d10fc6) |
Mocking a method that returns
Job
fails in android instrumentation testsSteps to Reproduce
I made an MWE for this issue.
https://github.com/saied89/MockK_coroutine_Job_android_MWE
Please pay attention that while Instrumentation test and jvm test are identical, only jvm test runs to completion with instrumentation test throwing.
The failing mock:
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: