c++ - 谷歌模拟 : how can I "EXPECT " that no method will be called on a mock

标签 c++ googletest googlemock

我想测试在某些失败的情况下不会在模拟对象上调用任何方法,使用谷歌模拟。 所以代码是这样的:

auto mocObj = new MockObj;
EXPECT_NO_METHOD_CALL(mocObj); //this is what I'm locking for

auto mainObj = new MainObj(mocObj , ......and other mocks); // here I simulate a fail using the other mock objects, and I want to be sure the no methods are called on the mockObj

最佳答案

没有必要明确告诉我们不会调用任何方法。如果您将日志记录级别设置得足够高,则在调用方法时应该会收到一条消息(如果没有设置期望值)。

除此之外,您可以这样设置期望:

EXPECT_CALL( mockObj, Foo(_) ).Times(0);

关于所有方法。

关于c++ - 谷歌模拟 : how can I "EXPECT " that no method will be called on a mock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8648243/

相关文章:

c++ - std::iostream 如何缓冲?

c++ - 如何否定 gtest assert 或 expect that 中的匹配器?

c++ - 将模拟对象分配给 protected 成员

c++ - 使用 std::shared_ptr 检测循环引用

c++ - 在 EXPECT_CALL 中使用 google mock 的 EXPECT_THAT?

c++ - 简单参数转发(我的签名应该是什么?)

c++ - 定义寄存器堆栈数组

c++ - 该语句如何检查 "T cannot be compared to nullptr"?

c++ - Visual C++ 项目 : best unit test setup

c++ - 记录谷歌测试