Content
- Summary
- Test Doubles
- State Verification
- Fake
- Stub
- Spy
- Behavior Verification
- Mock
- Example --- ATM and Bank Server test case
- Why we need to use Mock in this test case
- We want to test the implementation of ATM.
- ATM will connect to Bank Server.
- We don't want to connect to the real Bank Server while testing. Therefore, we mock the Bank Server with GMock.
- How to do it?
- What should the mock do?
- Test case structure
- What does ON_CALL offer?
- You can use it with Matchers
- EXPECT_CALL vs ON_CALL
- What does EXPECT_CALL offer?
- Matchers / Composite Matchers
- Wildcard Matcher: _
- Cardinality --- User can call the function multiple time, user can define the return value one by one.
- Uninteresting and Interesting Mock Functions
- Uninteresting vs Unexpected
- Meaning
- Unexpected --- When the test case called a function that is not matched any mock rules.
- Uninteresting --- That function is uninteresting it there's not even a single EXPECT_CALL
- Enforcing the Order of Calls

- GMock Actions
- Sticky Rules
- All rules remain active even after we have reached their invocation upper bounds.
- GMock Advanced Topics
- Checkpoints
- Mocking Private or Protected Methods
- Mocking Overloaded Methods
- Mocking Template classes
- Mocking Non-Virtual Classes
- In this case, you cannot do dependency injection for unit testing.
- You need to change your testing class into template based implementation. In this example, that will be the ATM class.
- Mocking a Free Function
- You will need to wrap it into a class with base class so that you can separate the test class and real class
- Delegate to Fake
- You need this when you have some functions you don't want to mock them.
- Delegate to Real
- Criticisms of Google Mock
All powerpoint slides
- Microsoft OneDrive. (n.d.). https://1drv.ms/f/s!Ajo1PqhJNlsagblpZouIZMT614eoOA?e=Q3E9Iu
Learnt from here
- Arisaif. (2022b, March 11). Google Test and Mock Platform - Part 3: Mocking Classes and Functions with GMock [Video]. YouTube. https://www.youtube.com/watch?v=vxCH4AuVRgo

Comments
Post a Comment