Could someone describe in a few words what the main differences between JUnit 3 and 4 are?
Asked
Active
Viewed 1.8k times
43
-
7This is not actually a question of opinion. There are very factual and explicit differences between Junit 3 and 4 and the enumeration of such is of interest. – dcow Dec 22 '14 at 22:32
1 Answers
68
Java 5 annotations for setup and teardown (
@before
and@after
) instead ofsetUp()
andtearDown()
.don't need to extend TestCase anymore.
@Test
annotation replacestestSomeMethod()
naming convention.static imports
for asserts.Junit theories, which allow you to separate data sets from the test itself.

Sumit Singh
- 15,743
- 6
- 59
- 89

Paul Sanwald
- 10,899
- 6
- 44
- 59
-
4Just came across this which may be interesting http://www.asjava.com/junit/junit-3-vs-junit-4-comparison/ – user716468 Nov 26 '13 at 00:17
-
2
-
Refer this : http://junit.org/apidocs/org/junit/experimental/theories/Theories.html and https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0CDIQFjADahUKEwjugLOA87DHAhXDT44KHa4YCuM&url=http%3A%2F%2Fwww.javacodegeeks.com%2F2013%2F12%2Fintroduction-to-junit-theories.html&ei=QzzSVa7THcOfuQSusaiYDg&usg=AFQjCNGab9k_SfHZgdih-g2gRIEH07THVw&sig2=S9IYicBahLQ0rBib7DrTdA&bvm=bv.99804247,d.c2E – zytham Aug 17 '15 at 19:57
-
one more.. names doesn't need to start with "test" therefore pattern "testXXXXX" can be ignored with JUnit4. – Ewoks Aug 24 '15 at 13:36