43

Could someone describe in a few words what the main differences between JUnit 3 and 4 are?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
cody
  • 6,389
  • 15
  • 52
  • 77
  • 7
    This 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 Answers1

68
  1. Java 5 annotations for setup and teardown (@before and @after) instead of setUp() and tearDown().

  2. don't need to extend TestCase anymore.

  3. @Test annotation replaces testSomeMethod() naming convention.

  4. static imports for asserts.

  5. 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
  • 4
    Just 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
    can you give an example or a pointer to elaborate on the above point 5? – liang Dec 20 '13 at 18:20
  • 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