I hate unit testing, I also love unit testing; not like Marmite, I always hate Marmite.
Unit testing is one of those things, in my experience at least, that every developer dislikes doing – particularly in a TDD team. Working using TDD feels completely backwards (initially, at least); you don’t have any code to test, so how could you possibly write any tests? But more importantly, unit testing takes the developer away from the developing, from what they enjoy, and in their mind, from what they’re employed to do.
This is wrong, and developers should know it – deep down, I actually think a lot of developers do know this – testing is not a bad thing, and certainly isn’t something to avoid like a plague. Automated testing is a painful process to start adhering to, and even painful to support as the software grows. I’d definitely say that it’s worth it over time, because as the source code continues to grow, and be refactored, the automated testing should at least give peace of mind when making changes.
I don’t have any references for anything I’ve said so far, it’s all opinion, and I’ve yet to work anywhere that has unit testing nailed down; I’ve certainly worked in places where the intention is there, and there’s even some unit tests, but they’re often not kept up-to-date, or cover a tiny percentage of the codebase. Personally, in a non-professional sense, there’s one reason I like unit testing – the passing of tests.
This may just be me, but I feel a huge sense of satisfaction when I’ve written a unit test and I see the little green ticks against the test (I’m very aware this is an image of Visual Studio/ReSharper’s unit testing UI, but I’m sure unit test results are similar in other IDE’s). I always have the small niggling doubt in the back of my mind that the test is wrong, but that’s when I can go back and check. The test has passed, so now I can relax knowing that the result of what I was testing is what the expected result was. Sure I’m going to get tests that fail, but that’s the point, it highlight’s that something is wrong (even if that something is the test itself).
I’m not always for unit testing, however. I’ve seen some places where people insist on unit testing a UI; I don’t get that, it seems like a lot of effort for very little gain, particularly as UI’s are much more prone to changing than back-end/business logic. I’m happy for someone to prove me wrong if there’s a convincing argument for why I’m wrong, but as things stand I can’t think of any time I’d want to unit test a UI.
All that being said, however, I still can’t find bring myself to write a unit test, so for now I’ll have to rely on good old-fashioned test plans.