2
abstract trait MyApi {
def getResult()(implicit ec: ExecutionContext): Future[String]
}
以下的方法不工作:模擬不帶參數但隱含參數
val m = mock[MyApi]
(m.getResult _).expects() returning "..."
它失敗:
java.lang.ClassCastException: org.scalamock.MockFunction1 cannot be cast to org.scalamock.MockFunction0
注:http://scalamock.org/user-guide/advanced_topics/給出的例子是隻有當方法至少有一個參數時纔有用。所以我們不能使用如下解決方案:mocking methods which use ClassTag in scala using scalamock
解決的辦法是:(m.getResult() (_:ExecutionContext))。期望(*)返回「...」,如果你更新你的答案,我會接受它。 – douglaz
@douglaz - done-Ed –