[ACCEPTED]-differences between 2 JUnit Assert classes-assert
The old method (of JUnit 3) was to mark 15 the test-classes by extending
junit.framework.TestCase. That inherited 14
junit.framework.Assert itself and your test class gained the ability 13 to call the assert methods this way.
Since 12 version 4 of JUnit, the framework uses
Annotations for 11 marking tests. So you no longer need to 10 extend
TestCase. But that means, the assert methods 9 aren't available. But you can make a static 8 import of the new
Assert class. That's why all 7 the assert methods in the new class are 6 static methods. So you can import it this 5 way:
import static org.junit.Assert.*;
After this static import, you can use 4 this methods without prefix.
At the redesign 3 they also moved to the new package
org.junit that 2 follows better the normal conventions for 1 package naming.
Prefer the newest 2 one, especially when running JDK5 and higher 1 with annotation support.
There is in fact a functional change:
org.junit.Assert will 2 complain if you use the two-argument
assertEquals() with 1
junit.framework.Assert will silently autobox it.
I believe they are refactoring from
junit.framework to 1
junit.framework.Assert is maintained for backwards compatibility.
In Android Studio (and so in IntelliJ too), you 5 can globally exclude
junit.framework from auto-import proposal.
You 4 can set the scope between
Project. If you don't 3 have projects which use JUnit 3 you can 2 safely stay with IDE scope.
Preferences 1 -> Editor -> General -> Auto Import
I did a rough source code compare and there 5 are no serious changes. A lot of comments 4 were added in
org.junit.Assert and some refactorings are 3 done. The only change is the comparison 2 with
Arrays. There are some code cleanups, but 1 there's (imho) no functional change.
More Related questions