meekrosoft/fff
FreeA testing micro framework for creating function test doubles
FreeFree tier
About meekrosoft/fff
fff (Fake Function Framework) is a micro-framework for creating fake C functions for unit tests. It is header-only (fff.h) and uses macros to automatically generate fake functions with call counting, argument capture, and return value control. Designed for embedded C testing, it reduces the boilerplate of hand-writing mock functions while supporting advanced features like return value sequences, variadic functions, and GCC function attributes.
Key Features
Header-only (single fff.h include)
Macro-based fake definition (FAKE_VOID_FUNC, FAKE_VALUE_FUNC)
Automatic call counting (call_count)
Argument value capture per call (arg0_val, arg1_val, ...)
Return value sequences and custom return value delegates
Argument history tracking with configurable depth
Support for variadic functions
Support for GCC function attributes
Easy reset of fakes between tests
User-defined argument history size
Pros & Cons
Pros
- Saves time by eliminating manual fake function writing
- Lightweight and easy to integrate (single header file)
- Works with any C testing framework
- Provides detailed call history and argument capture
- Supports complex mocking scenarios like return value sequences and delegate functions
- Variadic function support for flexible APIs
Cons
- Only supports C, not C++ classes or methods
- Macro-based implementation may complicate debugging and error messages
- Requires manual reset of fakes between tests to avoid state leakage
- Limited to function-level mocking, not full object mocking
Best For
Unit testing C codeEmbedded systems testingReplacing real functions with fakes in test suitesTesting interactions with hardware abstraction layersSimulating complex return value behavior in integration tests
FAQ
Is fff header-only?
Yes, you only need to include fff.h in your test suite. No compilation or linking required.
How do I fake a function that returns a value?
Use the FAKE_VALUE_FUNC macro followed by the return type and argument types. For example: FAKE_VALUE_FUNC(int, my_function, int, char*).
Can I capture argument values from each call?
Yes, for each faked function, variables like arg0_val, arg1_val, etc. are created to capture the argument values of the most recent call.