a little background: I wish to unit test my code which gets built into a shared object file, say libabc
. This code also calls libjson-c
and libcurl
functions.
I am planning to write function-wise tests for each function in product code, mocking calls to other functions from libabc
, libjson-c
and libcurl
. Now I can't arrange all tests for a given file a.c
in a single test file as in each test I would be required to mock different functions from a.c
.
Also, in a single test, I would want to mock all function calls to libjson-c
and libcurl
so that I won't have to link (gcc -lcurl -ljson-c
) the dependencies and this requires writing __wrap
functions for all the functions called from a.c
. But since each test case would want some particular code to be present in the wrapped functions, I can't just wrap them once and for all.
Any ideas around how are the tests with CMocka authored and arranged? Should I create a separate test file that gets compiled in an executable for tests of a product code function?