Mockitopp logo

Mockitopp

Free

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 dep

FreeFree tier
Type
Open Source

About Mockitopp

A C++ mocking framework inspired by the ideas developed for Mockito by Szczepan Faber et al. It provides similar construction semantics for creating mock objects, leading to smaller, more readable test cases. The framework uses ABI and template techniques to dynamically construct mock delegate classes that intercept calls intended for any pure virtual abstract base class (interface). It offers a simple descriptive domain-specific language for stubbing behavior, verification, and argument matching. Designed to be lightweight, it helps create simpler, less brittle test cases with less maintenance overhead. Limitations: only supports pure virtual abstract base classes; cannot stub non-virtual functions; may produce unexpected results with hybrid classes.

Key Features

Uses ABI and template techniques to create mock delegate classes
Intercepts calls for pure virtual abstract base classes (interfaces)
Provides stubbing behavior, verification, and argument matching
Lightweight framework with a simple descriptive domain-specific language
Similar construction semantics to Mockito for smaller, more readable test cases
Open source under MIT license

Pros & Cons

Pros
  • Lightweight and easy to integrate
  • Inspired by Mockito provides familiar semantics
  • Simple descriptive DSL reduces boilerplate
  • MIT license allows free use in commercial projects
  • Low maintenance overhead
Cons
  • Only supports pure virtual abstract base classes (interfaces)
  • Cannot stub non-virtual functions
  • May produce unexpected results when mocking hybrid classes with state or internal dependencies
  • Limited documentation beyond basic examples in wiki

Best For

Unit testing C++ code that depends on abstract interfacesMocking dependencies in embedded systems testingCreating simpler, less brittle test cases for C++ projects

FAQ

What compilers are supported?
The README mentions compatibility with various compilers but does not list them explicitly. Check the wiki for supported compilers.
Does Mockitopp support mocking non-virtual functions?
No, the framework only works for virtual functions declared in the target class to mock. It cannot be used to stub calls to non-virtual functions.
Can I mock classes that are not pure abstract base classes?
In some cases it may be possible to mock a class that is not pure abstract (i.e., hybrid class with both virtual and non-virtual functions), but you may encounter unexpected results if the object maintains state or has internal wired dependencies.