JUnit 5.4.0 release enhances the next generation Java testing framework
JUnit 5 released with much fanfare, and the updates just keep on coming. Now, the latest version 5.4.0 adds some new features, bug fixes, and breaking changes. Come see what’s been added and improved upon. New to JUnit 5? There’s no better time than now to upgrade and start with this popular unit testing framework.
JUnit version 5.4.0 released on February 7, 2019 with a few important bug fixes, deprecations, features, and improvements. Since the release of JUnit 5, the popular Java testing framework has entered the next generation. The new version is programmer-friendly and was deemed to have “the potential to define testing on the JVM”.
Let’s take a look under the hood of this new update and see what improvements are in store for Java developers.
Referring to the changelog, here’s what’s been added and improved:
The latest features include:
junit-platform-reportingartifact containing a
LegacyXmlReportGeneratingListenerthat generates XML reports using a format which is compatible with the de facto standard for JUnit 4 based test reports that was made popular by the Ant build system.
junit-platform-testkitartifact containing a Test Kit API for testing the execution of a
TestEnginerunning on the JUnit Platform.
- If a container or test fails, the root cause and suppressed exceptions are now included in the stack trace printed by the
ConsoleLaunchernow sanitizes user-provided display names before printing them to the console.
- Common whitespace characters such as
\rare replaced by a standard space character, and all other ISO control characters are emitted as a single dot (
- Common whitespace characters such as
ModifierSupportclass providing an API for extension and test engine authors to inspect modifiers of classes and members.
AnnotationSupportprovides new methods for finding annotated fields and their values.
ReflectionSupportprovides new methods for finding fields and reading a field’s value.
- Exceptions reported due to failed reflective operations such as loading a class, reading a field’s value, or looking up a method by name now include the original exception as their cause to make it easier to debug underlying issues.
LauncherAPI now provides an
execute(TestPlan, TestExecutionListener…)method that allows one to execute a previously discovered
@RunWith(JUnitPlatform.class)no longer executes test discovery twice.
- Implementations of
HierarchicalTestEnginemay now add behavior that wraps around the invocation of
Node.after()using the new
SEE ALSO: How well do you know your JUnit trivia?
Take note of these deprecations and breaking changes to avoid a messy situation:
- The JUnit Platform Maven Surefire Provider (
junit-platform-surefire-provider) has been discontinued and is no longer released as part of JUnit 5. Please use Maven Surefire’s native support for running tests on the JUnit Platform instead (requires Maven Surefire 2.22.0 or higher).
TestPlan.add(TestIdentifier)has always been considered internal and is now deprecated. While calls from third-party code will continue to work for the time being, IDEs and build tools should remove any such code as soon as possible
#JUnit 5.4 has been released!
Single dependency for Jupiter API, Engine, and Params
Test Kit for testing engines and extensions
Built-in TempDir extension
Display name generator API
Test execution order API
TestWatcher extension APIhttps://t.co/fgVCiphWpT
— JUnit Team (@junitteam) February 7, 2019
The next generation
Do we have any newcomers to this testing framework?
Wondering what makes it different from other previous versions? The biggest difference, JUnit 5 is composed of different modules from three projects: JUnit Platform, JUnit Jupiter, and JUnit Vintage. (Fun fact: The name Jupiter was picked because it’s the fifth planet for JUnit 5.)
If you haven’t upgraded, now is a perfect time. The user guide is a great place to start on your journey. Frankly, we suggest that anyone who programs in Java should have it in their familiar toolkit.