I have seen many crazy methods to get access to private variables when unit testing. The most mind blowing I've seen is #define private public
.
However, I've never seen anyone suggest turning off private variables at the compiler level. I had always just assumed that you couldn't. I've complained to many a developer that unit testing would be a lot easier if you could just tell the compiler to back off for this one file.
Then I stumble across the -fno-access-control gcc compiler option. It's so obviously the perfect way to unit test. Your original source files are unmodified, no injected friends just for the unit test, no recompiling with bizarre preprocessor magic. Just flick the 'no access control' switch when compiling your unit tests.
Am I missing something? Is this the unit testing silver bullet I hope it is?
The only disadvantage I see is the gcc specific nature of the technique. However, I assume MSVS has a similar flag.