通过以下测试,我有一个无效的存根设置。mockrequestBuilder
使用 param 存根"INCORRECT"
,而被测类使用"/socket"
.
我在 JUnit 中使用 Mockito 的经验告诉我,运行时的调用将导致null
. 但是,我看到的是误报。测试通过 &requestBuilder
正在返回模拟request
,即使它是用 调用的"/socket"
。
为什么是这样?是否与拥有多个期望有关?如果是这样,最终的期望是最重要的,它应该失败。
class ChannelSpec extends Specification with Mockito with ScalaCheck with ArbitraryValues { def is = s2"""
A Channel must
send an open request to /socket with provided channel name on instantiation $sendToSocket
"""
def sendToSocket = prop{(name: String, key: Key, secret: Secret) =>
val requestBuilder = mock[(String, Seq[Map[String, String]]) => Req]
val request = mock[Req]
val httpRequestor = mock[(Req) => Future[String]]
val result = mock[Future[String]]
val params = Seq(Map("key" -> key.value, "timestamp" -> anyString, "token" -> anyString), Map("channel" -> name))
requestBuilder("INCORRECT", params) returns request
httpRequestor(request) returns result
new Channel(name, key, secret, requestBuilder = requestBuilder, httpRequestor = httpRequestor)
there was one(requestBuilder).apply("INCORRECT", params)
println("expecting " + request)
there was one(httpRequestor).apply(request)
}