A header-only C/C++ testing micro-framework for creating fake function test doubles with minimal boilerplate.
Fake Function Framework (fff) is a micro-framework for creating fake function test doubles in C and C++ unit tests. It automatically generates fake functions that track calls, capture arguments, and control return values, eliminating the need to manually write stub code. It solves the problem of tedious boilerplate when testing low-level or embedded systems code.
C and C++ developers writing unit tests for embedded systems, hardware drivers, or any code requiring function isolation. It's especially useful for those working in environments where manual stub creation is time-consuming.
fff reduces testing overhead with a header-only, zero-dependency design that works in both C and C++ environments. Its simple macro-based API makes it easy to integrate into existing test suites without complex setup, unlike heavier mocking frameworks.
A testing micro framework for creating function test doubles
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Simply include fff.h to start faking functions, making it trivial to add to any C or C++ project without external dependencies or complex build configuration, as emphasized in the README's philosophy.
Macros like FAKE_VOID_FUNC automatically generate fakes that track call counts, argument values via argN_val, and history arrays, reducing manual test setup boilerplate for embedded code.
Can fake variadic functions such as fprintf using FAKE_VALUE_FUNC_VARARG, a rare feature in lightweight libraries, with examples in the README for custom delegate handling.
Reset functions like RESET_FAKE and FFF_RESET_HISTORY allow for clean state resets between tests, promoting reliable unit testing as demonstrated in the setup examples.
Primarily designed for C functions, it struggles with mocking C++ member functions or virtual methods directly, requiring workarounds like typedef bridges for function pointers.
Heavy reliance on preprocessor macros can lead to cryptic compiler errors and make the API less intuitive, especially for complex signatures with multiple parameters.
Missing built-in matchers, expectation setters, or verification helpers found in frameworks like Google Mock, forcing manual checks of arg_val fields and custom fake assignments.
Features like argument history length are fixed at compile-time via defines (e.g., FFF_ARG_HISTORY_LEN), limiting runtime adaptability without recompilation.