我正在尝试模拟一个带有call-by-name参数的方法调用:
import org.scalatest.WordSpec
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
trait Collaborator {
def doSomething(t: => Thing)
}
trait Thing
@RunWith(classOf[JUnitRunner])
class Test extends WordSpec with MockitoSugar {
"The subject under test" should {
"call the collaborator" in {
// setup
val m = mock[Collaborator]
val t = mock[Thing]
// test code: this would actually be invoked by the SUT
m.doSomething(t)
// verify the call
verify(m).doSomething(t)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我主要对Mockito感兴趣,因为我正在使用它,但我有兴趣看看是否有任何主要的模拟框架能够进行这种测试.测试在运行时在线上失败,verify出现类似的错误
Run Code Online (Sandbox Code Playgroud)Argument(s) are different! Wanted: collaborator.doSomething( ($anonfun$apply$3) <function> …