代码:
<asp:ContentPlaceHolder ID="ContentHead" runat="server">
运行此测试时出现问题或至少出现意外行为:
如果我评论出具体的class MockDefault : public Verifyingcalls::DefaultSCI_OCB {
public:
MOCK_METHOD0(op, void());
MOCK_METHOD1(op1, void(sc_integer param1));
MOCK_METHOD2(op2, void(sc_boolean param1, sc_integer param2));
};
TEST_F(VerifyCallCount, after3Cycle) {
MockDefault defaultMock;
EXPECT_CALL(defaultMock, op1(_)).Times(AtLeast(4));
EXPECT_CALL(defaultMock, op2(_,_)).Times(AtLeast(4));
EXPECT_CALL(defaultMock, op1(5l)).Times(AtLeast(2));
EXPECT_CALL(defaultMock, op1(7l)).Times(AtLeast(2));
EXPECT_CALL(defaultMock, op2(true, 7l)).Times(AtLeast(2));
EXPECT_CALL(defaultMock, op2(true, 5l)).Times(AtLeast(2));
...
}
测试工作正常,但如果我没有得到此失败:
错误:
EXPECT_CALL's
问题:
我的问题是,为什么测试失败?
我假设函数Actual function call count doesn't match EXPECT_CALL(defaultMock, op2(_,_))...
Expected: to be called at least 4 times
Actual: never called - unsatisfied and active
..\gtests\VerifyCallCount\VerifyCallCount.cc:123: Failure
被调用至少4次,至少两次使用参数5和两次使用参数7.那么为什么测试失败?
答案 0 :(得分:1)
我认为在这种情况下是期望
EXPECT_CALL(defaultMock, op2(true, 7l)).Times(AtLeast(2));
EXPECT_CALL(defaultMock, op2(true, 5l)).Times(AtLeast(2));
被调用并且
EXPECT_CALL(defaultMock, op2(_,_)).Times(AtLeast(4));
未被调用,因为其他两个匹配。使用gmock
时,只执行一次匹配,而不是所有匹配。例如EXPECT_CALL
可以返回值。如果调用多个匹配,那将不是唯一的。