也许是一个技巧问题,我的问题是,如果我写:
EXPECT_CALL(mock, handleMessage(_)).Times(0); // expectation #1
EXPECT_CALL(mock, handleMessage(Pointee(IsLike(aSpecificMessage)))); // expectation #2
...并且方法handleMessage
被调用一次,但使用不同的参数(不是aSpecificMessage
),那么失败看起来像:
Mock function called more times than expected - returning default value.
Function call: handleMessage(0x8b5378)
Returns: false
Expected: to be never called
Actual: called once - over-saturated and active
Google Mock 不会打印关于为什么参数与预期 #2 中的谓词不匹配的诊断。这大概是因为期望 #1 是第一个失败的(?)。
如果我省略了期望 #1,那么失败是冗长的,大致如下:
Google Mock tried the following 1 expectation, but it didn't match:
../../test/Test.cpp:143: EXPECT_CALL(mock, handleMessage(Pointee(IsLike(aSpecificMessage))))...
Expected arg #0: points to a value that <....>
Actual: 0xfeaf18, which points to <.....>
我正在使用自定义匹配器IsLike
,并且遇到了生成非常明确的不匹配原因的麻烦,我希望将它们打印出来。我也不想放弃期望#1,因为它位于“默认”部分,默认情况下,我不希望在其余测试中调用该模拟。