8

我不认为 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;
    }
};
4

1 回答 1

3

我自己找到了答案:在此处为需要此答案的其他人添加它:

解决方案是使用 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;
    }
};
于 2011-10-16T22:02:33.713 回答