I have a scenario where my coworker is writing functions that I wish to use in my module. He wrote the unit tests for his module, and I am writing the unit tests for mine. Naturally I would like to mock his functions for my test.
The production code is written in C and compiled as a library separately from the Unit test code. At link time, we are overwriting the object code of the production for the Mock version. However this overwrites ALL calls to that particular function instead of just in my unit tests.
Here is an example.
Using CPPUTEST, I have MockSupport_c.h
at my disposal. So I write up a mock for his function. Ex
real function:
int read_bytes(int count)
{
// for loop read the bytes
return success;
}
I call the above with my function that I want to test
int read()
{
return read_bytes(256);
}
The test module looks something like the following:
// create the mock
int read_bytes(int count)
{
mock_c()->actualCall("read_bytes");
return 1;
}
// test the code
TEST(group, test_name)
{
mock_c()->expectOneCall("read_bytes");
read();
mock_c()->checkExpectations();
}
When the unit test is compiled, the linker will replace the production code implementation with the mocked version; but it will do it for all calls to that function. So my coworkers unit tests now call mocks, when it should be testing his actual calls.
How do I get the mocks to only apply during my tests, and not overwrite my coworkers calls?
Or am I just way off base with how all of this works?