![](/img/trans.png)
[英]How to expect a function to be called in a specific frequency by using Google Test (Mock)?
[英]google mock : how can I “ EXPECT ” that no method will be called on a mock
我想测试在某些失败的情况下,不会使用谷歌模拟在模拟对象上调用任何方法。 所以代码是这样的:
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);
在所有方法上。
创建一个StrictMock
; 任何意外的方法调用都将失败。
对所有类方法使用 Exactly(0)。
基数将设置为零,因此您预计不会有电话
您也可以使用StrictMock
代替NiceMock
。 这将在任何“无趣的”调用中失败,即,每当调用模拟方法时,但EXPECT_CALL
。
请参阅此处的Google Mock 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.