当我有一个模拟方法的调用预期失败时,测试仍在通过。乍一看,我认为会有某种标志来控制这种行为,但我找不到。
万一需要更多的上下文,这在我身上发生了任何期望,但作为示例,我有以下示例,使用自定义Matcher。
// Expectation:
Foo expectedFoo;
Foo foo;
EXPECT_CALL(foo, GenerateEvent(1, FooEq(&expectedFoo)));
//Matcher:
MATCHER_P(FooEq, expected, "")
{
return false;
}
如果调用foo.GenerateEvent(1, new Foo)
,则预期动作将按预期方式失败,但测试仍会通过,如下所示(由于隐私问题,我们不得不对名称进行了修改,希望我不会弄乱最终结果)。
[ RUN ] Test.FooTest
unknown file: error:
Unexpected mock function call - returning directly.
Function call: GenerateEvent(1, 0D386FDC)
Google Mock tried the following 1 expectation, but it didn't match:
Foo.cpp(307): EXPECT_CALL(foo, GenerateEvent(1, FooEq(&expectedFoo)))...
Expected arg #1: foo eq 012FF238
Actual: 0D386FDC
Expected: to be called once
Actual: never called - unsatisfied and active
[ OK ] Test.FooTest (15 ms)