What’s new in JUnit 5 for Java testing
The JUnit testing framework for Java has just moved to version 5. Unlike previous releases, JUnit 5 features modules from several subprojects, including:
- Platform, for launching testing frameworks on the JVM and defining the TestEngine API via a command line.
- Jupiter, for programming and extension models for writing tests and extensions and then (via plugins) building them within JUnit, Gradle, or Maven.
- Vintage, for running JUnit 3 and 4 tests on the JUnit 5 platform.
In Jupiter, a developer can use annotations as meta-annotations, in which you define an annotation that automatically inherits the semantics of meta-annotations—a new programming model in JUnit. Also, Jupiter lets test constructors and methods to have parameters, allowing for more flexibility and enabling dependency injection for constructors and methods.
JUnit 5 requires Java 8 or higher version at runtime. But developers still can test code previous versions of the Java Development Kit. JUnit 5 artifacts do not ship with compiled module descriptors for JDK 9, but there are accommodations for JDK 9. Tests can be run on the
java class path; in this regard, there are no changes between Java 8 and 9, according to documentation. Also, running JUnit Jupiter tests on the module path is implemented by
pro, a Java 9-compatible build tool.