Thursday, October 23, 2008

JUnit 4.5 in Eclipse 3.4

I was quite disappointed when I realized that Eclipse 3.4 (Ganymede) still uses JUnit 4.3. JUnit 4.4 was released last summer so it shouldn't be rocket science to it a part of Ganymede, which was released this summer. Well, I guess it all comes down to lack of time and resources. Of course, it could also be because of compatabilty issues between JUnit versions, or something similar.

Luckely, it quite easy to use a newer version of JUnit in Eclipse. By simply adding the new JUnit JAR to the classpath of an Eclipse project and removing the JUnit 4 Library (that is, the entry in 'Java Build Path' with an icon that looks like a pile of books), the project will run the test-case with the new JUnit. Of course, your other projects will still use JUnit 4.3. We have done this at work with JUnit 4.5 and it works really good.

I recommend you to do this, since there are some really nice features in JUnit 4.5; the possibility do distinguish between assumptions and assertions, and better descriptions of failed assertions, for instance.


Anonymous said...

Tried working with junit 4.5 but this method did not work. I am still stuck with ant-junit.jar which comes with eclipse 3.4

Martijn van der Woud said...

Worked perfectly! (Eclipse 3.2)

Liisa said...

Can any of you help me figure out how JUnit 4.5 features compare to TestNG 5.8?

-new to java unit testing

Togge said...

ant-junit.jar sounds like the ANT+JUnit integration, not JUnit itself. Go to Project->Properties->Build Path and check the name of the JUnit jar-file. Sorry, but I can't help you much more than that without knowing more details.

Sorry, I wish I could help you but have have no experience at all with TestNG. I wish I had, though...