The latest release of JUnit i.e. JUnit 5 has been around for quite sometime. My tests work fine on JUnit 4 and want to know the potential reasons to migrate to JUnit 5.
Here is a brief run-down of the major advantages of JUnit 5 over JUnit 4 [PS - These advantages might motivate you to move to JUnit 5 ]:
-
In JUnit 4, entire framework is a part of a single jar file. On the other hand, JUnit 5 comprises of three major components - JUnit Platform, JUnit Jupiter, and JUnit Vintage. In JUnit 5 Maven Dependency, you have the option to download jar files of the individual components that make up the JUnit 5 framework. Overall, there is more granularity in JUnit 5 and you can import jar file(s) important for your project.
-
JUnit 5 lets you run multiple test runners at one time. On the other hand, JUnit 4 lets you run only one test runner at a time.
-
One of the primary requirements of JUnit 5 is that it requires Java version 8 (and above). This essentially means that you can leverage the advantages offered by Java 8, something which is not possible with JUnit 4. The primary reason is that JUnit 4 works only with Java version 7 (and below).
Though there are changes in the annotations in JUnit 5, you can still run JUnit 4 tests with JUnit 5 by migrating the tests to JUnit 5. You would need changes in pom.xml and relevant changes have to be done for including the respective JUnit 5 packages.
Hope this helps. Do let me know if you require more support.