The pImpl idiom and Testability
- by Rimo
The pImpl idiom in c++ aims to hide the implementation details (=private members) of a class from the users of that class.
However it also hides some of the dependencies of that class which is usually regarded bad from a testing point of view.
For example if class A hides its implementation details in Class AImpl which is only accessible from A.cpp and AImpl depends on a lot of other classes, it becomes very difficult to unit test class A since the testing framework has no access to the methods of AImpl and also no way to inject dependency into AImpl.
This has been a problem for me lately and I am beginning to think that the pImpl idiom and writing testable code don't mix well.
Has anyone come across this problem before? and have you found a solution?