我正在尝试在某些测试代码中使用WithArg
。我正在尝试编译的代码如下所示:
using ::testing::_;
using ::testing::Invoke;
using ::testing::WithArg;
EXPECT_CALL(myMock, MockMethodThatTakesAString(_))
.WithArg<0>(Invoke(this, &TestClass::FunctionThatTakesAString))
.Times(4);
当我尝试编译时,我收到错误
error: ‘class testing::internal::TypedExpectation<void(const std::basic_string<char>&)>’ has no member named ‘WithArg’
我在这里做错了什么?
答案 0 :(得分:2)
WithArg<N>
是一个动作适配器,而不是一个成员函数。要使用它,请在WillRepeatedly
子句中对其执行操作:
EXPECT_CALL( myMock, MockMethodThatTakesAString(_) )
.Times(4)
.WillRepeatedly(WithArg<0>(Invoke(this
, &TestClass::FunctionThatTakesAString)));