Reputation: 3743
Consider this class under test:
class A
{
public:
bool isTrue();
void doSomething();
};
I want to test doSomething
which calls isTrue
in its implementation.
But I also want to set expectations on the isTrue
method.
Is there a best practice with google test how one can mock methods of the class under test?
Upvotes: 2
Views: 5461
Reputation: 4674
Turning my comment into an answer...
There's a little hack you can use. Define a derived class like so:
class B : public A {
public:
MOCK_METHOD0(isTrue, bool());
using A::doSomething;
};
This obviously only works if isTrue
is virtual
.
Beware: Check your company's testing guidelines regarding "code made especially for testing" instead of testing the real code. In your situation (legacy codebase) this might be okay.
Upvotes: 5