我有一个接口的扩展功能,如下所示:
import javax.jms.ConnectionFactory
fun ConnectionFactory.foo() {
println("do some stuff")
}
如何模拟函数 foo?
请注意,我在http://mockk.io/#extension-functions中看到了类和对象的方法,但它不起作用。我试过这个:
import io.mockk.classMockk
import io.mockk.every
import org.junit.Test
import javax.jms.ConnectionFactory
class ExtensionFunctionTest {
@Test
fun mockExtensionFunction() {
val connectionFactory = classMockk(ConnectionFactory::class)
every { connectionFactory.foo() } returns println("do other stuff")
connectionFactory.foo()
}
}
它抛出异常:
io.mockk.MockKException: Missing calls inside every { ... } block.