我正在使用 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中做到这一点?也许使用另一个库?