July 29, 2008

Java 5.0 and Junit 4

Posted by Sudhindra Rao

While working on some Java code and working with Java 5.0 and Junit4.4 I started by writing some examples and tests.

I would say it was a very pleasant experience working on the new JUnit with Java 5. Parts of code became a lot clearer and easy to read. Lot of clutter was hidden behind more aptly named annotations(For the critics of everything annotated - "Right now we are just talking about good things").

I ran across a lot of issues when using Junit4(most of it was my ignorance.) Some of the following links helped me understand how Junit4 was different.
Junit FAQ
Junit 4 Basics
What's new in Junit 4.4

NoClassDefFoundError with Junit 4.4 (This was the first error I had to deal with when running tests using the command line or ant)
Converting tests from Junit 3.8 to JUnit 4.4

When using Junit4 on command line the following JUnit3 command

java -classpath lib\junit.jar;build\prod\com\MyProject\;build\test\com\MyProject junit.textui.TestRunner com.MyProject.MyTest

becomes

java -classpath lib/junit-4.4.jar;build org.junit.runner.JUnitCore com.MyProject.MyTest

Note the change of runner class in Junit4. Happy Testing with Junit4.

0 comments:

Welcome