lundi 23 mars 2015

Testing a unit for which a specific private method invocation is required?

I have a testing dilemma:


I'm writing a unit test for Unit A. The method I'm about to test is func(B param). In the (non testing) code the only place where the func(..) is called is in class C, it's also the only place in the project where variables of type B can be instanciated (to be sent as parameters to the func(B param), so the instanciation method is private.


Now, I'm not sure how should I create a B instance inside the Unit test. Of cause I can change private to public in a method declaration of the method which creates B, but I don't feel right about it, since it'll expose the method to the rest of the project.


I can also simply duplicate the B creation method into the Unit test class, but I hate duplicating code. Is there some known best practice for such cases?


Thanks a lot, Dima


Aucun commentaire:

Enregistrer un commentaire