The pImpl idiom and Testability

Posted by Rimo on Stack Overflow See other posts from Stack Overflow or by Rimo
Published on 2010-05-06T23:29:43Z Indexed on 2010/05/06 23:38 UTC
Read the original article Hit count: 133

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about testing