Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

JUnit 5.3 brings console output capture, assertThrow enhancements and parallel test execution

Save for later
  • 2 min read
  • 12 Sep 2018

article-image

A new version of JUnit v5.3 was released last week. There are some changes and new features like parallel test execution, enhancements to AssertThrows, and others in this new version.

JUnit is a popular unit testing framework for the Java which has been instrumental to the rise of test-driven development.

Below are some of the key highlights of JUnit 5.3.

Capturing output from a console


It is now possible to capture System.out and System.err output using a TestExecutionListener in Junit 5.3. Capturing console output may not be a frequent need, but can become necessary in some cases such as when working on legacy code bases where statements are being written to console and viewing them can be useful. There are two steps to get this working, implementing a TestExecutionListener and configuring surefire to start capturing console output.

Enhancements to AssertThrows


The assertThrows assertion is updated to display the value a method returns. This works only if the method runs successfully and returns a value and no exception is thrown. It can be helpful for debugging a failing test case.

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at AU $24.99/month. Cancel anytime

Parallel test execution


Parallel test execution is now enabled and can be configured via build files. This can be a pom.xml, build.gradle etc. The parallel test execution behavior can be changed at both, method and class levels with the annotations: @Execution and @ResourceLock. For detailed information on configuring and using parallel test execution in JUnit 5, check out the user guide.

Other changes


There are also some libraries and tools updated that are used with JUnit like filtering changes with native support, enhanced mockito dependency injection support, updates to AssertJ Soft Assertions and opentest4J.

JUnit 5.3.1 was released on September 9, shortly after JUnit 5.3 and there are some minor fixes. There is another major change where variants of assertThrows() introduced in JUnit 5.3.0 that accepted ThrowingSupplier arguments are now removed.

For a full list of bug fixes and changelogs, visit the JUnit website and to learn how to use the features, check out the user guide.

Unit testing with Java frameworks: JUnit and TestNG [Tutorial]

Unit Testing Apps with Android Studio

Unit Testing in .NET Core with Visual Studio 2017 for better code quality