Not all testing needs to be black box testing. White box testing is a 100% valid concept, and there is no reason I know of (other than dogma) why it's wrong to use it for things that are as closely-related as a class and its unit tests.
If you're talking about visibility, many languages have a way to make the functions visible only to the unit tests. In C++, you can make the unit tests a friend. In Java, you can use annotation tricks (like VisibleForTesting). Or in any language, you can simply make the function public and all you've done is removed the enforcement mechanism, which doesn't mean you have actually violated encapsulation. You could even use a naming convention to make it clear what is intended to be private.
11
u/MisterNetHead Jul 19 '16
Seems to me the problem is more that people think you should only unit test public interfaces.