定义了一个mock:
MOCK_CONST_METHOD4(scan,
int(const int64_t timeout, const ObServer & server, const ObSqlScanParam & scan_param, ObMsSqlRpcEvent & result));
下面一种mock方法是正确的,先注册mock,然后再调用:
EXPECT_CALL(async, scan(_,_,_,_))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(callback_func_async));
ASSERT_TRUE(OB_SUCCESS == async.scan(a, b, c ,d));
而下面这种是错误的,调用scan的时候会发现定义了scan的mock,但没有指定探测到scan后的行为:
ASSERT_TRUE(OB_SUCCESS == async.scan(a, b, c ,d));
EXPECT_CALL(async, scan(_,_,_,_))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(callback_func_async));
GMokc中的Expect_Call是运行时注册的,注册必须先于实际调用的发生。