使用Mockito,是否可以验证是否使用间谍或模拟调用/未调用函数,而不提供实际参数?例如,如果我有一个类或对象:
class MyClass{
def f(x : Int) = x
}
object MyObject{
def f(x : Int) = x
}
我希望能够说出类似的内容:
val my_class = mock[MyClass]
// Do something that causes method f of MyClass to be called
there was one(my_class).f // Doesn't give arguments
val my_object = spy(MyObject)
// Do something that causes method f of MyObject to be called
there was one(my_object).f // Doesn't give arguments
我只想验证方法是否被调用,而不是它接收到特定的参数。此外,当我检查没有调用函数时:
there was no(my_object).f
我不想验证它是不是用某些参数调用的,而是根本没有调用它。
有没有办法做到这一点?
答案 0 :(得分:9)