lundi 2 mars 2015

Is it bad practice to make methods public solely for the sake of unit testing?


I have a class with a public method. It has other methods that 'assist' with the purpose of the public method. The public method must be tested. However, I also want to unit test the private methods.


It would be impossible for my unit tests to call private methods and test them in isolation, so they must be public.


The problem here is that I'm left with code that, I feel, has been written with a lack of respect for OOP convention, purely for the sake of being able to unit test it.


Am I right in amending the access of methods purely for 'testability'? Or should I be rethinking and refactoring the structure as a whole to separate out the functionality of the private methods (despite the fact they don't do a lot at all and may, at times, resemble small helper methods)?





Aucun commentaire:

Enregistrer un commentaire