[英]google mock : how can I “ EXPECT ” that no method will be called on a mock
I want to test the in case of some fail no method will be called on a mock object , using google mock.我想测试在某些失败的情况下,不会使用谷歌模拟在模拟对象上调用任何方法。 so the code be something like:所以代码是这样的:
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
There are no needs to explicitly tell that no methods will be called.无需明确说明不会调用任何方法。 If you set the logging level high enough, you should get a message if a method is called (if no expectation is set).如果您将日志记录级别设置得足够高,则在调用方法时应该会收到一条消息(如果未设置预期)。
Other then that, you can set expectations like this :除此之外,您可以设置这样的期望:
EXPECT_CALL( mockObj, Foo(_) ).Times(0);
on all methods.在所有方法上。
Create a StrictMock
;创建一个StrictMock
; any unexpected method call will be a failure.任何意外的方法调用都将失败。
Use Exactly(0) for all your class methods.对所有类方法使用 Exactly(0)。
the cardinality will be set to zero so you are expecting no calls基数将设置为零,因此您预计不会有电话
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.