Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is running tests with JUnit 3.x vs JUnit 4.x still a best practice?

I haven't looked at this in a while, but if I recall correctly both ant and maven still rely on JUnit 3 for unit tests (as of maven 2.09 the default POM file still has JUnit 3.81).

Does it still make sense to stick to JUnit 3 instead of using the latest and greatest? Any good reason I might be missing?

like image 282
agnul Avatar asked Dec 01 '08 13:12

agnul


2 Answers

I don't see a reason to stick to the 3.x versions. Most tools have been compatible with 4.x for a while now. The only reason I would stick to 3.x is in a java 1.4 environment (because there is no other way).

By the way, maven is switching to Java 5 in 2.1, so there is a chance they will propose junit 4.x

like image 83
Somatik Avatar answered Sep 23 '22 02:09

Somatik


JUnit 4 has lots of advantages over 3.x. The most important is that you no longer have to extend TestCase, nor do your test methods have to begin with "test." It's all annotation-based now. You can also add the Hamcrest matchers, which gives you a really nice and expressive way of writing test assertions.

If you're stuck on a pre-Java-1.5 project, you may have to stick with JUnit 3.x, though.

like image 42
Joey Gibson Avatar answered Sep 21 '22 02:09

Joey Gibson