I know this is an older question, but it seems that nobody has shared the relatively good method that I prefer, so here it goes:
Change the method you wish to test from private
to protected
. For other classes, the method is still going to be private
, but now you can derive a "testing" class from your base class that exposes the private functionality you want tested.
Here's a minimal example:
class BASE_CLASS {
protected:
int your_method(int a, int b);
};
class TEST_CLASS : public BASE_CLASS {
public:
int your_method(int a, int b) {
return BASE_CLASS::your_method(a, b);
}
}
Of course you will have to update your unit tests to run your tests on the derived class instead of the base class, but after that, any change made to the base class will be automatically reflected in the "testing" class.