Simple mocking for C++
Clone or download
Latest commit c6a1058 Jan 3, 2017

Mockitopp Build Status

A C++ mocking framework inspired by the ideas developed for Mockito written by Szczepan Faber, et al. The purpose is to provide similar construction semantics for creating mock objects leading to smaller, more readable test cases. It is designed to be a lightweight framework allowing you to mock dependencies for a system under test using a simple descriptive domain specific language. The goal is to help create simpler, less brittle test cases; ultimately, leading to less maintenance overhead in the future.


Basic usage examples and other information can be found in the wiki documentation.

  1. Stubbing
  2. Behavior Verification
  3. Argument Matching
  4. Common Issues
  5. Supported Compilers

How does it work?

MockitoPP uses ABI and template techniques to create mock delegate classes that intercept calls intended for any abstract base class you care to model. The techniques used to construct the mock objects are similar to the techniques used by Automatic Mock Object for C++ (amop), Hippo Mocks, and Member Function Pointers and the Fastest Possible C++ Delegates. By exploiting the compiler's ABI class layout we can dynamically construct a mock delegate class to provide minimal stubbed functionality used during unit testing.


This framework really only supports pure virtual abstract base classes (i.e. interface). The mocking construction only works for virtual functions declared in the target class to mock. You cannot use it to stub calls to non-virtual functions. In some cases it may be possible to mock a class that is not a pure abstract base class (i.e. hybrid class containing both virtual and non-virtual functions), but you may encounter unexpected results if other objects are expecting the mock object to operate under normal circumstances (i.e. maintain state) or have internal wired dependencies that operate on the object's state.