Trompeloeil
FreeA thread safe header only mocking framework for C++14 using the Boost Software License 1.0
FreeFree tier
About Trompeloeil
Trompeloeil is a thread-safe, header-only mocking framework for C++11 and C++14. It provides macros to create mock classes, set expectations on calls, and verify interactions. Key capabilities include wildcard matching, relational matchers, sequence control for call ordering, side effects, return value specification, and forbidden call declarations. Distributed under the Boost Software License 1.0, it integrates with various unit test frameworks and includes comprehensive documentation such as a cheat sheet, cook book, and FAQ.
Key Features
Header-only library – no build step required
Thread-safe mock objects
Supports C++11 and C++14
Boost Software License 1.0
MAKE_MOCK and MAKE_MOCK0 macros for mock methods
REQUIRE_CALL for mandatory expectations
FORBID_CALL for disallowed calls
Wildcard (_) and relational matchers (gt, ge, lt, le, eq, ne)
Sequence control (trompeloeil::sequence) for ordered calls
LR_SIDE_EFFECT and SIDE_EFFECT for side effects on parameters
Pros & Cons
Pros
- Header-only: easy to drop into any project
- Thread-safe design allows concurrent testing
- Free and open source with permissive Boost license
- Rich matcher and sequence control for precise expectations
- Comprehensive documentation (cheat sheet, cook book, FAQ)
- Wide compiler compatibility (tested on many compilers)
Cons
- Requires C++11 or later – not usable with older C++ standards
- Macro-based API can lead to naming conflicts and reduced type safety
- Header-only model may increase compilation times in large projects
Best For
Unit testing C++ classes that depend on interfaces or virtual functionsIsolating code under test by replacing dependencies with mock objectsVerifying call order and interaction patterns in integration tests