News

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

2 min read

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.

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.

Read next

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

Prasad Ramesh

Data science enthusiast. Cycling, music, food, movies. Likes FPS and strategy games.

Share
Published by
Prasad Ramesh
Tags: Javajunit

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago