"fallenrogue" Under Leon's hat.

Tue Feb 10

When do I Unit Test?

so, when do I test?

so, how do I test?

Am I doing it wrong?

Well, the answer to that last one is yes. Yes, you’re doing it wrong and you’re not alone. Unit testing is one of those things that has got a lot of attention lately because those that have given over to it love it and see the value yet others who have not or can not do not see the value and instead fall back to their old habits.

Now, their old habits were probably successful. That’s why they have blogs and jobs and people are linking to them on their sites. They have an opinion about something that they have experience with. They have a poor experience and therefore set out to share their opinion in the hopes that they can validate their sanity. “Everyone else says testing is awesome, but I think it sucks, I’d better write a blog post!”

You could say the same about me too. Sure, you could. If you want to, go ahead. I will not care. What I am trying to say is that the negative attitudes that I frequently encounter when discussing unit tests are always around a failed attempt at unit testing due to fundamentally misunderstanding the point. The above “am I doing it wrong” article doesn’t have any code samples to discuss just some 80/20 metrics (made up of course) and conjecture based on one person’s experience.

Validate all you want. That’s fine but at least try to understand that which you’re trying to do. It’s more than writing a single test here or there. There’s a lot more subtlety to the art of unit testing and if it feels bad you may be doing it wrong. If so, find someone doing it right and pair program with them. You’ll figure it out soon enough.

Comments (View)
blog comments powered by Disqus