samedi 18 juillet 2020

Kotlin Mockk: no answer found for

I was trying to mock a HttpClient class in my test, but I've always encountered the error of

no answer found for: HttpClient(#2).executeRequestAsync

I've also tried to spyk or mock the class in relaxed mode, such as:

var httpClient = mockk<HttpClient>(relaxUnitFun = true)

My mock code was:

var httpClient = mockk<HttpClient>()
every { httpClient.execute(any(), any()))} returns "something"

But all not working, I still got the error traces of:

no answer found for: HttpClient(#2).execute() ** IntervalFunction$$Lambda$126/0x00000008004a7840@2545d052, true, lambda {}, http.HttpClient$execute$, continuation {})
io.mockk.MockKException: no answer found for: HttpClient(#2).execute(, continuation {})
    at io.mockk.impl.stub.MockKStub.defaultAnswer(MockKStub.kt:90)
    at io.mockk.impl.stub.MockKStub.answer(MockKStub.kt:42)
    at io.mockk.impl.recording.states.AnsweringState.call(AnsweringState.kt:16)
    at io.mockk.impl.recording.CommonCallRecorder.call(CommonCallRecorder.kt:53)
    at io.mockk.impl.stub.MockKStub.handleInvocation(MockKStub.kt:263)
    at io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation(JvmMockFactoryHelper.kt:25)
    at io.mockk.proxy.jvm.advice.Interceptor.call(Interceptor.kt:20)
    at com.{name}.http.HttpClient.executeRequestAsync(HttpClient.kt:170)
    at com.{name}.http.HttpClient.executeRequestAsync$default(HttpClient.kt:151)

Aucun commentaire:

Enregistrer un commentaire