"Uninteresting mock function call" exception when mocking a function with a template base class

4.5k Views Asked by At

I have a base class A:

template <typename Type>
class A {
public:
    virtual const std::string& GetName() const = 0;
    virtual Type GetDefault() const = 0;
}

And a derived class B:

class B : public A<bool> {
public:
  const std::string& GetName() const override {return "bla"; }
  bool GetDefault() const override {return false;}
}

I want to Mock class B and its methods:

class MockB: public B {
public:
  MOCK_CONST_METHOD0(GetName, const string&());
  MOCK_CONST_METHOD0(GetDefault, bool());
};

Test:

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

But I keep getting 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.

It's used by the following method:

template<typename ValueType>
ValueType GetCustomSetting(const A<ValueType>& a) const

Which inside calls

a.GetName();

I've tried using MOCK_CONST_METHOD0_T but it didn't work as well.

0

There are 0 best solutions below