2

Possible Duplicate:
differences between 2 JUnit Assert classes

I have two junit-4.8.1.jars in my class path and my IDE's autocomplete is giving me the following two Assert classes:

  • junit.framework.Assert
  • org.junit.Assert

Which one should I use???

Community
  • 1
  • 1

3 Answers3

2

I prefer org.junit package in all things JUnit. It's the source URL that the code comes from. The other is legacy that's left so it doesn't break old code.

Pick one and be consistent.

duffymo
  • 305,152
  • 44
  • 369
  • 561
2

To quote a duplicate...

JUnit 3.X: junit.framework.Assert JUnit 4.X: org.junit.Assert

Prefer the newest one, especially when running JDK5 and higher with annotation support.

Community
  • 1
  • 1
David
  • 19,577
  • 28
  • 108
  • 128
0

Niether, use MatcherAssert and Hamcrest with assertThat instead of assertTrue / assertFalse

MatcherAssert

John B
  • 32,493
  • 6
  • 77
  • 98
  • Why not org.junit ? What's Hamcrest ? – Mr_and_Mrs_D Oct 20 '13 at 19:55
  • 1
    So, JUnit and Hamcrest are linked. There are a small set of Hamcrest `Matchers` built into the junit jar. Notice that the `Assert` class has a method `assertThat` that takes a `Matcher`. Additional there are Hamcrest libraries (hamcrest-all & hamcrest-core) that provide a very large number of Matchers. For example, if you need to check that two lists are equal, JUnit would just error saying they were not equals but Hamcrest would tell you which elements don't match: `IsIterableContainingInOrder` (also `IsIterableContainingInAnyOrder`) as a couple examples. – John B Oct 21 '13 at 10:40