I have two unit tests that share some state (unfortunately I can't change this since the point is to test the handling of this very state).
TEST(MySuite, test1)
{
shared_ptr<MockObject> first(make_shared<MockObject>());
SubscribeToFooCallsGlobal(first);
EXPECT_CALL(*first, Foo(_));//.RetiresOnSaturation();
TriggerFooCalls(); // will call Foo in all subscribed
}
TEST(MySuite, test2)
{
shared_ptr<MockObject> second(make_shared<MockObject>());
SubscribeToFooCallsGlobal(second);
EXPECT_CALL(*second, Foo(_)).Times(1);
TriggerFooCalls(); // will call Foo in all subscribed
}
If I run the tests separately, both are successful. If I run them in the order test1, test2, I will get the following error in test2:
mytest.cpp(42): error: Mock function called more times than expected - returning directly. Function call: Foo(0068F65C) Expected: to be called once Actual: called twice - over-saturated and active
The expectation that fails is the one in test1. The call does take place, but I would like to tell GoogleMock to not care after test1
is complete (in fact, I only want to check expectations in a test while the test is running).
I was under the impression that RetiresOnSaturation
would do this, but with it I get:
Unexpected mock function call - returning directly. Function call: Foo(005AF65C) Google Mock tried the following 1 expectation, but it didn't match: mytest.cpp(42): EXPECT_CALL(first, Foo(_))... Expected: the expectation is active Actual: it is retired Expected: to be called once Actual: called once - saturated and retired
Which I have to admit, confuses me. What does it mean? How can I solve this?
std::shared_ptr
) - so , how, according to you, gmock shall recognize they shall not participate in next test? My point is that they are subscribed - so they are called - but they expected to be called only once – Cornelius