我有一个基类A:
template <typename Type>
class A {
public:
virtual const std::string& GetName() const = 0;
virtual Type GetDefault() const = 0;
}
以及派生类B:
class B : public A<bool> {
public:
const std::string& GetName() const override {return "bla"; }
bool GetDefault() const override {return false;}
}
我想模拟class B
及其方法:
class MockB: public B {
public:
MOCK_CONST_METHOD0(GetName, const string&());
MOCK_CONST_METHOD0(GetDefault, bool());
};
测试:
MockB mock;
const std::string key = "something";
EXPECT_CALL(mock, GetName()).WillRepeatedly(ReturnRef(key));
SomeClass.method(mock); // this calls A<T>.GetName() and raises an exception
但我不断遇到异常:
unknown file: error: C++ exception with description "Uninteresting mock function call - returning default value.
Function call: GetName()
The mock function has no default action set, and its return type has no default value set." thrown in the test body.
它通过以下方法使用:
template<typename ValueType>
ValueType GetCustomSetting(const A<ValueType>& a) const
内部通话
a.GetName();
我尝试使用MOCK_CONST_METHOD0_T
,但效果不佳。