JUnit 4 In 10 Minutes
I have been using JUnit 3, pretty much since I started doing test based development. (OK OK I haven’t been doing it for that long.) Unit tests have become a standby in my general development now though. I also really love the features of Java 5 (the new looping constructs, generics (templates if you speak C++), and annotations). In particular I love what annotations does to unit testing. However the past couple projects I have worked on required Java 4 (grrrr….). So I was particularly excited to get the opportunity to jump on a new project and use JUnit 4.
Unfortunately, the documentation is shockingly slim on the JUnit web site. Pretty much just java doc, which doesn’t really give you the “this is standard operating procedure.” And it also doesn’t say “if you did this in 3 now do this in 4.” It does have a cookbook for the most basic of tests, but I am a more sophisticated user of JUnit than that. I want to know how to do all the complicated stuff I always do. Enter an excellent java today article by Ralf Stuckert. Just enough detail to convert all my tests from 3 to 4, with no extra text. And he adds in examples of three new features: timeout, ignore, and parameterized testing. Very useful. I’ll be using that as a reference until I get used to the new style.