我正在使用scalamock來模擬一個包含一些重載方法的類,但我收到了一些錯誤。嘲笑重載方法
例如:
val out = mock[PrintStream]
(out.print _).expects("cmd \r\n")
引發以下錯誤:
[error] [...]/src/test/scala/chili.scala:19: ambiguous reference to overloaded definition,
[error] both method print in class PrintStream of type (x$1: String)Unit
[error] and method print in class PrintStream of type (x$1: Array[Char])Unit
但是,如果我嘗試使用:
(out.print(_: String)).expects("cmd \r\n")
我也得到一個錯誤:
[info] [...]/src/test/scala/chili.scala:19: Unable to resolve overloaded method print
[info] (out.print(_: String)).expects("cmd \r\n")
[info] ^
[error] [...]/src/test/scala/chili.scala:19: value expects is not a member of String => Unit
[error] (out.print(_: String)).expects("cmd \r\n")
有什麼辦法可以在scala中做到這一點?也許使用另一個庫?
很好的答案。謝謝 – simao