My favorites | Sign in
Project Logo
             
People details
Project owners:
  trevor.pounds
Project committers:
jimpurbrick

MockitoPP C++ Mocking Framework

A C++ mocking framework inspired by the ideas developed in the original Mockito mocking framework for Java 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 and lead to better software design practices.

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) and Member Function Pointers and the Fastest Possible C++ Delegates. By exploiting the compiler's ABI layout of an abstract base class we can dynamically construct a mock delegate class to provide minimal stubbed functionality used during unit testing.

Requirements

Boost C++ Libraries (required)

Google C++ Testing Framework (required - xUnit tests)

Hamcrest (optional - argument matching)

C++ Technical Report 1 (optional - regex argument matching)

Limitations

This framework really only supports pure virtual abstract base classes (i.e. interface). In reality, the mocking construction only works for virtual functions declared in the class you are trying to mock. This means you cannot use this framework to stub calls to non-virtual functions. So while it is likely possible to mock a class that is not a pure abstract base class (i.e. a class consisting of virtual and non-virtual functions), you will most likely encounter unexpected results if other objects are expecting the mocked object to operate as if they were not mocked (i.e. maintain state).









Hosted by Google Code