I am trying to write a Unit Test for a function. This function is static and in a file, say FileA.cpp, though it is not a member of any class.
In FileA.cpp there is also a static variable defined. In another file say FileB.cpp there is a usage of this static variable.
My existing Unit Test code does not reference FileA.cpp, since none of its functionality is being tested so far. It does however test functionality of FileB.cpp. To facilitate this static variable reference, a fake variable is defined in Main.cpp of the Unit Test project (I am using GoogleTest framework).
But now I need to test FileA.cpp. When I add the file in the Makefile, I am getting a "multiple definition" error for this static variable.
I tried introducing a .h file (Say GlobalVars.h) with the same name in the Production and Testing project respectively and moving the variable there but it does not seem to fool the compiler. The FileA.cpp instance in the test project still tries to access the GlobalVars.h of the production code and I get a double definition again.
Any ideas how could I break this dependency?