Clarification on interleaving of EXPECT_CALL()s and calls to mock functions in the case of multiple mocks #4128
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.
-
Your example does not fall into undefined behavior as long as the following conditions are met:
Your test code is valid and adheres to GMock's behavior. Setting expectations on different mock objects sequentially and invoking the |
Beta Was this translation helpful? Give feedback.
-
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