2 Oct 2006 16:53
Testing private methods
michael_coxeter <mco <at> mwdata.dk>
2006-10-02 14:53:43 GMT
2006-10-02 14:53:43 GMT
Hi Folks, Is it good to test private methods or not? Most people seem to think that private methods should be tested by testing the public methods correctly. And this would seem like good advice. However, when it comes to refactoring is it nice to have tests on all your code? I recently looked at a refactoring a class which only had one public method. The tests that existed for the public method seemed a little brittle as it is hard to perceive all the possibilities that need testing. The code had many private methods and I was itching to refractor it. So to make my job easier I moved the private methods into an implementation class, made them public and wrote new tests for these. Anyway the refactoring went well and I am pleased with the result. My new tests are somewhat linked to the implementation I chose for the original public method. Are they worth keeping around? Or are these an example of temporary tests that have served a purpose and can now be thrown away?(Continue reading)
I wonder if there is catchier phrase for "unintended side-effect?"
Michael Feathers
RSS Feed