【发布时间】:2015-10-02 18:30:59
【问题描述】:
我正在尝试在一些测试代码中使用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’
我在这里做错了什么?
【问题讨论】:
-
.WillRepeatedly(WithArg<0>(Invoke(this, &TestClass::FunctionThatTakesAString))).Times(4) -
@PiotrSkotnicki 这样做会导致运行时错误
Failure .Times() cannot appear after .InSequence(), .WillOnce(), .WillRepeatedly(), or .RetiresOnSaturation(). -
将
Times移到WillRepeatedly之前 -
@PiotrSkotnicki 啊,但是将
Times(4)放在WillRepeatedly之前确实有效。谢谢! -
@PiotrSkotnicki 也许写一个答案?
标签: c++ unit-testing googlemock