谷歌模拟:我如何"预测"在模拟上不会调用任何方法

ang*_*a d 27 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
Run Code Online (Sandbox Code Playgroud)

BЈо*_*вић 48

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

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

EXPECT_CALL( mockObj, Foo(_) ).Times(0);
Run Code Online (Sandbox Code Playgroud)

在所有方法上.


eph*_*ent 16

创建一个StrictMock; 任何意外的方法调用都将失败.


Gia*_*ini 5

对所有类方法使用 Exactly(0)。

基数将设置为零,因此您预计不会有电话