Prateek
05/16/2024, 8:07 AMwhenever(mockObj.callExtFunc()) return something
this would throw error something like:
java.lang.AbstractMethodError: Receiver class kotlin.jvm.functions.Function2$Subclass0 does not define or inherit an implementation of the resolved method 'abstract java.lang.Object invoke(java.lang.Object, java.lang.Object)' of interface kotlin.jvm.functions.Function2. at ....
Any thoughts.
Thank you.David Kubecka
05/16/2024, 8:12 AMPrateek
05/16/2024, 8:19 AMMichael Krussel
05/16/2024, 11:44 AMPrateek
05/20/2024, 12:11 PMHttpClient.post
from Ktor which is defined as an extension function in Ktor.
So I have written conditions in my unit test as mentioned below:
mockkStatic("io.ktor.client.request.BuildersKt")
coEvery {
httpClientMock.post(any<String>(), any<HttpRequestBuilder.() -> Unit>())
} coAnswers { httpResponseMock }
But I still get this error when executing coEvery
block.
What could I be missing?Prateek
05/20/2024, 12:51 PMktor-client-mock
and handled differently but would appreciate if I can get an answer for my problem above.Michael Krussel
05/20/2024, 1:16 PMBuildersKt
should be buildersKt
since the file is lowercase in GitHub. But using ktor-client-mock
would be my choice of solution. In general using a mocking library is my last choice when creating a test, because it typically creates the most fragile tests.AdamW
05/20/2024, 1:21 PMMockEngine
or the services
block in your TestApplicationEngine
instead of a mocking library for this, which should be the last resort in all circumstances.Prateek
05/20/2024, 1:25 PMAdamW
05/20/2024, 1:34 PMPrateek
05/21/2024, 3:47 AM