I have a unit test class Tester; I want it to access private fields of a Working class.
class Working {
// ...
private:
I did this by using a copy of my class header file in my test that is missing the "private" access specifier. The copy is generate by the makefile in the test directory so that the copy is regenerated if the original changes:
perl -ne 'print unless m/private:/;' < ../include/class_header.h > mock_class_header.h
and the 'test' make target depends on mock_class_header.h.
This grants access to all the private member variables in the test, even though the real library was compiled with these member variables being private.