【发布时间】:2021-05-12 07:24:11
【问题描述】:
我有一个场景,我希望对模拟对象上的函数进行一些调用,然后对于某些代码路径,我需要确保不调用该函数,然后再调用它。有没有办法做到这一点?
EXPECT_CALL(mockObj, 1);
foo(1);
// Expect this call at the first invocation of foo(2)
EXPECT_CALL(mockObj, 2);
foo(2);
// These calls should not call my mockObj again, the above expectation is
// intended for the first invocation of foo(2)
foo(2);
foo(2);
// And now, i expect it to be called
EXPECT_CALL(mockObj, 3);
foo(3);
我可能会检查 EXPECT_CALL(mockObj, 2);只调用了预期的次数,但我还想确认它仅在第一次调用 foo(2) 时调用,而不是在随后调用 foo(2) 时调用。 你能告诉我在 gmock 中实现这一点的任何方法吗?
【问题讨论】:
-
RetiresOnSaturation可能会有所帮助。
标签: c++ googletest googlemock