A recent post
to the JUnit mailing list has me thinking. I got into JUnit because I really liked
writing test cases. But I really respect some people that have been really frustrated with JUnit and decided there are better uses of their time than gung-ho unit testing. Is there more going on here than personal preference? I think there might be.
Have you tried working with JUnit on a simple, non-database-backed, non-web-fronted application? Perhaps a personal toy, like Sudoku
or currency conversion
? Here is a place JUnit can easily shine--you have a green field to build cleanly encapsulated objects with clear responsibilities. It's on code like this that I learned to love test-driven development, and JUnit for doing TDD in Java.
If you try something like that, and you still don't like it, then move on. I do not recommend slogging away with something that makes you suffer just because someone else said it was a good idea. (Unless that person's your boss, in which case I'm sorry, and please hang around here
for some concrete advice.) Come back to it in a year or so.
If, however, you do like it, then when you come back to your "real-world" tasks, with database integration, JSP web pages, fuzzy specifications, and everything else that we all know is out there, maybe you'll find ways to make these tasks a little more like the green field "toys" you started with. Or maybe you'll at least have gained some motivation to spend some more time trying to test some of the harder components.
I've heard complaints that many of the JUnit tutorial material ignores these "real world" issues, and there's some point to that. Although it's not necessary for databases and web frameworks to be test-adverse (I think that Ruby on Rails shows this pretty well), many are, and we could do a better job pointing to the excellent concrete resources out there for resolving these conflicts. On the other hand, gung-ho unit testing is a delicate new relationship. The fact that a first date happens over candlelight and Chianti doesn't mean the relationship won't eventually survive a 17-hour car trip with two cranky young children. But first things first, perhaps?