I have looked at other discussions about this topic (on StackOverflow) however the other questions seem to be language specific whereas this is not language specific and I'm considering no longer using private methods, classes, and modules.
I want to test my private methods, classes, and modules so that I can more easily locate bugs. To allow me to do this I'm considering no longer using private methods, classes, and modules for two reasons, (1) I see no reasonable way of testing a private method, class, or module without injecting test code or using some sort of "magic" and (2) to improve code reuse. Note that I'm not considering no longer using private variables and properties because data needs protecting and does not provide behaviour therefore it does not need to be public during testing.
As a lame example, if you're writing a module called OneOperations
that has two public methods addOne
and subtractOne
, and two private methods add
and subtract
. If you were not allowing yourself to have private methods you would put the two private methods into another module (basicOperations
) where they are public and import those methods inside the OneOperations
module. From this you should now be able to write testing code for all the methods in both modules without injecting code. An advantage of this is that the methods add
and subtract
can now be used in other modules by importing the basicOperations
module (2 - improving code reuse).
I have a feeling this a bad idea, but I lack the real world experience to justify not doing this, which is why I've posted this question on StackOverflow.
So, how do you test your private methods, classes, and modules? Is not writing private methods, modules, and classes a potential solution?