Question about Unit Testing
I got on a little late when it comes to unit testing, but I'm definitely sold on it. However I came across something unexpected the other day and it threw me for a loop. I'm curious to see how other people handle the issue. In the past, I basically wrote tests to validate every public method and property that I had. In most cases I would test the affirmative condition (that it did what it was supposed to), the negative (that it would produce 'incorrect' results if the inputs were bad and a few other things. Now I know, the first two there are mathematical equivalents but the reason I did it was that suppose you had a method that b/c of a bug, always returned true. If you only tested in the affirmative, you'd get 'true' values returned however you're code was *not* working correctly.
Anyway, we've recently hired two developers in our department and at the same time, I've been put in charge of 'quality control'. Namely, I'm setting the rules for using Unit Testing , NDoc , Fx Cop , NAnt , Cruise Control .NET etc. So I was working with one of them explaining our code coverage policy when I decided to walk through building tests for a class that was written a long time ago before anyone was writing tests. So I create the tests for the public methods/properties and then I notice that a lot of work is being done in some of the private methods. So I write some tests up for them too. About 1/2 through it I realized there was going to be a problem. By design private members aren't going to be visible so how in the heck do I test them? The easy way is to make them public but changing the design of a class just so you can unit test it seems like DailyWTF material. So for the time being, I just wired in some test methods within the class itself but this too seems like a crazy way of getting there.
Ok, so I know the wrong way to accomplish what I want , which is to be able to test code which is private in addition to testing what's public. I know there's probably some glaringly simple solution to this but I sure haven't been able to figure it out - hopefully one of my brilliant readers can shed some light on it.