I start using gmock for my code recently, some of which rely on some other outside services or interfaces, so gmock is kind of perfect for me.
Say I have a trivial class A to mock
class A
{
void foo(int& bar) {
// will change bar
bar = GetingResultFromSomeOutsideService();
}
};
Now I create a mock class
class MockA: public A
{
MOCK_METHOD1(foo, void(int& bar));
};
In my test case, I try to mock the behavior of A::foo
of changing bar
with ON_CALL
, but I don't know how exactly.
For example, I want my MockA::foo
always set bar
to 1, so that my other codes invoking A::foo
will always get bar == 1
like this:
// some other piece of codes invoking A::foo
int bar = 0;
A my_a;
my_a.foo(bar);
cout << bar; // always output "1" with gmock
Any hint?