C++ Mocks Made Easy – An Introduction to gMock

Mock objects make unit testing easier and more effective. They cut code dependencies, make the tests fast and robust, make the test intent clear, and enable developers to easily test the interaction between components. While an invaluable technique, mocks haven’t caught on in the C++ land due to limitation of the language and lack of good tools. gMock is a library that makes C++ mocks easy and practical. A user would describe the interface he wants to mock and gMock will automatically generate the implementation. Then the user can control the generated mock using an intuitive Domain-Specific Language (embedded in C++) that resembles English. Announced in Q4 2007, gMock has been used in over 100 projects at Google.