This question already has an answer here:
- How do you unit test private methods? 28 answers
What is the best practice for accessing (and manipulating) class members that are private, when using MS factory unit testing? This is for VS 2013, C#.
I'm a beginner in using unit testing and test-driven development.
I'm unable to find anything in MSDN documentation... although documentation for VS2008 says "Visual Studio Team System tools provide unit tests with the ability to access them, even though the unit test file is a separate class." (ref here). As far as I can tell, no such tools exist for VS2013.
The only ways I can think of are:
- change the access modifier (from private to public, for example)
- add an accessor that is only available during DEBUG, using a preprocessor directive or the like (put in an
#if DEBUG
, for example).
I'd prefer to not use option one. After all, there is a reason it was marked as private in the first place.
I'd also prefer not to use option two, it doesn't seem to fit well with what I've learned about how unit testing should work so far.
Aucun commentaire:
Enregistrer un commentaire