[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fundamental question: How to resolve dependencies with mock objects


Hi,
 
starting to use unit tests for an existing project (embedded C), I currently try to use cmocka for this.
I have a lot of dependencies (e.g. to hardware) and interfaces to other devices that let me think I require mock objects to do a "simple simulation" of hardware/interfaces for unit tests.
So I started to integrate cmocka and now have a lack of basic understanding of the concept:
 
As far as I understand, I need to implement a wrapper function for every function I want to mock. As an example, for a mock of a function    int foo(char* c)    I write a function int    __wrap_foo ( char* c )   and give the option "--wrap=foo to the linker.
 
My question is:
If I want to implement unit tests for two modules A and B, and I want to have a mock version of B for unit test of A and a mock version of A for unit test of B -- how to implement this?
Because when I implement mock versions of all functions of A and of B and tell the linker to use these "wrappers" instead of the real functions, then my unit test executable will only contain the mock versions of all the functions. The "real" implementation of A and B will not be linked into the executable and therefore cannot be tested.
Or do I miss something?
 
best regards,
Frank

Follow-Ups:
Re: Fundamental question: How to resolve dependencies with mock objectsJakub Hrozek <jakub.hrozek@xxxxxxxxx>