Appendix A. Differences between JUnit 3 and JUnit 4
This appendix covers
- Changes between version 3.x and 4.x of JUnit
- API changes
- New features in JUnit 4.x
As you’ve probably seen, the new 4.x version of JUnit is a completely new framework. It’s more of a totally new project than a bug-fixing improvement of the old one. But it still deals with unit testing your Java code. That said, we will try to define all the differences between the latest version of JUnit and the 3.x version.
This section discusses the changes in the requirements for using JUnit.
JUnit 4 uses a lot from Java 5 annotations, generics, and static import features. Although the JUnit 3.x version can work with JDK 1.2+, this usage requires that the new version of JUnit be used with Java 5 or higher.
All of the JUnit 4.x test runners are able to execute JUnit 3.x tests with no modification whatsoever. But what about executing JUnit 4.x tests with the JUnit 3.x test runner? Now this is a trickier one, but it’s absolutely necessary to support so that external tools such as Ant or Eclipse can work with JUnit without needing an update.
The key is to use the JUnit4TestAdapter and wrap all of your tests like the one shown in listing A.1.