Faked Function Framework

Intro to faked-function-framework

Perhaps you’re doing embedded C programming and have been going through the motions of covering already written code by unit tests (as opposed to doing the development TDD style). Doing this, you’ve probably sometimes felt the pain of having to stub out an entire module, just to change the behavior of one single method, writing endless lines of repetitive empty method implementations. Or perhaps you find it hard to maintain your test code and share common stub traits?

In that case, perhaps you need to look at Mike Long‘s faked-function-framework (FFF) as suggested by James Grenning at this year’s BITsCon software conference.


Say, you want to stub a method with the signature:

void calculateBigThing(int seed);

Using FFF you can do it like this:

/* Preamble */ 
#include "fff.h" 

FAKE_VOID_FUNC1(calculateBigThing, int);

The statement above simply means fake (or stub, ignoring the cry of puritans) calculateBigThing as a function returning void, taking one int parameter.

Behind the scenes (using macros) FFF implements not only the stub, but also a mock like framework that makes it possible for you to write statements setting up expectations like this:

calculateBigThing_fake.return_val = 33;
ASSERT_EQUAL(expected, calculateBigThing_fake.arg0_history[0]);

ASSERT_EQUAL being your favorite xUnit (C/C++) testing framework assertion macro (CppUnit, CUnit, CppUTest, …).

You can also stub functions returning a value with up to 10 args and even set up sequences of return values.


Check out the work of Mike Long on

Also check out James Grenning articles on how to apply FFF dealing with low-level OS stuff.

And while you’re at it, read Mike Long’s excellent article on how to unit test operations on low level memory mapped variables using FFF.

We would like to help you

Morten Hoffmann


T: (+45) 3095 6416