1

在使用案例类作为参数的存根方法时,我有一个奇怪的行为。

我仍在试图理解为什么,但在一种情况下,我得到了一个

You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
    when(mock.get(anyInt())).thenReturn(null);
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
    verify(mock).someMethod(contains("foo"))

像这样打桩时

simpleTrait.anotherMethod(any[Param]) returns "Mock String"

我必须像这样改变它

simpleTrait.anotherMethod(Param(anyInt)) returns "Mock String"

在哪里

case class Param(val: Int)

trait SimpleTrait {
  def anotherMethod(someParam: Param): String
}

不过,这两种行为似乎都是等效的。

有任何想法吗?

4

0 回答 0