简体   繁体   English

在 spyk object 上存根方法立即调用原始方法

[英]Stubbing a method on a spyk object calls the original method immediately

for example the method例如方法

   class SomeClass() {
       fun login(listener: (Boolean) -> Unit ) {
            do some async logic and then call the listener with the result
      }
   }

   val spy = spyk(SomeClass())  {

          val completion = slot<(Boolean) -> Unit>()
         //this immediately calls the original login method
         every { login(capture(completion)) } answers {
              completion.captured.invoke(true)
         }
     }

trying to stub the login method immediately invokes it.试图存根登录方法会立即调用它。

Do you know how to just stub it and not invoke it?你知道如何只存根而不调用它吗?

If we look at the Mockk, maybe relaxed-mock ?如果我们看一下 Mockk,也许是很放松的模拟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM