我不认为minInvocation或maxInvocation相当于Mockito中的times().在那儿?
请看这个问题:Mockito和JMockIt之间的主要区别
任何人都没有回答过.
编辑
我自己找到了答案:在这里为需要此答案的其他人添加答案:
解决方案是使用DynamicPartialMocking并将对象传递给Expectations或NonStrictExpectations的构造函数,而不是调用该对象上的任何函数.
然后在Verifications部分中,调用要测量调用次数的对象上的任何函数,并设置times =您想要的值
new NonStrictExpectations(Foo.class, Bar.class, zooObj)
{
{
// don't call zooObj.method1() here
// Otherwise it will get stubbed out
}
};
new Verifications()
{
{
zooObj.method1(); times = N;
}
};
Run Code Online (Sandbox Code Playgroud)
我自己找到了答案:将其添加到此处以供其他需要此答案的人使用:
解决方案是使用 DynamicPartialMocking 并将对象传递给 Expectations 或 NonStrictExpectations 的构造函数,并且不在该对象上调用任何函数。
然后在 Verifications 部分中,对要测量其调用次数的对象调用任意函数,并设置 times = 您想要的值
new NonStrictExpectations(Foo.class, Bar.class, zooObj)
{
{
// don't call zooObj.method1() here
// Otherwise it will get stubbed out
}
};
new Verifications()
{
{
zooObj.method1(); times = N;
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1323 次 |
| 最近记录: |