C++ 谷歌模拟:我怎么能“期望”在模拟上不会调用任何方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8648243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
google mock : how can I " EXPECT " that no method will be called on a mock
提问by angela d
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
采纳答案by ephemient
Create a StrictMock
; any unexpected method call will be a failure.
创建一个StrictMock
; 任何意外的方法调用都将失败。
回答by B?ови?
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.
在所有方法上。
回答by Gianluca Ghettini
Use Exactly(0) for all your class methods.
对所有类方法使用 Exactly(0)。
the cardinality will be set to zero so you are expecting no calls
基数将设置为零,因此您预计不会有电话