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