Monday, November 24, 2008

Unit Testing Private Methods

I’ve been reading a lot recently about people’s opinions regarding the correctness of unit testing private methods. Personally, I don’t see anything wrong with testing them – after all, private or not, I want to know if the code is going to work!!!

Who cares if it’s private?

Granted, performing the tests on a private method can prove tricky. I use VSTS for my coding, thus I take advantage of the private accessor code that is generated for me when I create a test on a private method. I find it quite bizarre that someone would suggest not testing private code, rather you should unit test any public methods that make use of that private code. Tsk, rubbish. If I had a coder on my team with that attitude, I’d seriously question his sanity.