VS 2010 allows for private method unit testing. Is that a good idea? I have always heard that unit testing scenarios were for the public methods only. Should I bother with the private methods and properties?
Thanks Leo
In his infinite wisdom, Jon Skeet once wrote (in C# in depth) 'I’m happy to test whatever I can in the simplest manner possible'
IMHO, if you think a private method deserves unit testing then test it.
Two reasons to not test private methods:
1) Brittle tests. Private method is an implementation detail that you might want to change it in future without breaking tests.
2) Duplication. Code in private methods should be covered by the tests that exercise object using its public interface. If this is the case than you would simply be testing the same thing twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With