我正在尝试使用 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’
我在这里做错了什么?
最佳答案
WithArg<N>
是 Action 适配器,不是成员函数。要使用它,请将其作为 WillRepeatedly
中的一个 Action 子句:
EXPECT_CALL( myMock, MockMethodThatTakesAString(_) )
.Times(4)
.WillRepeatedly(WithArg<0>(Invoke(this
, &TestClass::FunctionThatTakesAString)));
关于c++ - 尝试在 GMock 代码中使用 WithArg;错误说它不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32913592/