Clarification on interleaving of EXPECT_CALL()s and calls to mock functions in the case of multiple mocks #4128
Unanswered
bpartemis
asked this question in
Community Help
Replies: 2 comments 2 replies
-
The scenario you described is a valid usage of multiple mock objects in a gtest. You are creating two separate mock objects, mockObjectA and mockObjectB, setting expectations on their methods, and making calls to the ClassUnderTest methods, methodA() and methodB(). The calls to the mock objects' methods will only occur if the corresponding ClassUnderTest methods are called, as you have set the expectations for these calls. It does not stray into the realm of undefined behavior. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all. I'm looking for clarification on the conclusion of this issue: #2828 (comment)
Its unclear to me if this constraint applies in a case where a gtest is using multiple mock class objects. Specifically the following scenario:
class MockA{
}
class MockB{
}
class ClassUnderTest{
ClassUnderTest(MockA& inMockA, MockB& inMockB);
void methodA();
void methodB();
}
TEST_F(ExampleMockTest, ExampleTest){
MockA mockA;
MockB mockB;
ClassUnderTest classUnderTest(mockA, mockB);
EXPECT_CALL(mockA, getThisInternalState())
.Times(1);
classUnderTest.methodA();
EXPECT_CALL(mockB, getThatInternalState())
.Times(1);
classUnderTest.methodB();
}
The code example is simplified, please let me know if any additional detail or clarification is needed. Does this stray in the realm of undefined behavior?
Apologies if this question has already been covered elsewhere. I did what I felt was a relatively exhaustive search both in this github project and on SO and didn't find anything.
Beta Was this translation helpful? Give feedback.
All reactions