'Y'

JUnit 5 – new approach, new functionalities

Junit is a testing framework for the Java programming languages. The Junit 5 version has been redesigned to solve certain challenges of previous versions. It also offers a new architecture, which offers the possibility of creating a hierarchy of tests, with assertions and assumptions, with dynamic and parameterized tests.

Junit is a testing framework for the Java programming languages. The Junit 5 version has been redesigned to solve certain challenges of previous versions. It also offers a new architecture, which offers the possibility of creating a hierarchy of tests, with assertions and assumptions, with dynamic and parameterized tests. This article is a short introduction to Junit 5 to help you understand the new architecture and functionalities that come with it.

As a unit-testing framework for the Java programming language, Junit is a very important tool for a test-driven development approach. It is part of a family of testing frameworks, called xUnit. Junit is tied at compiling time as a JAR and is the most frequently included external library in Java projects.

TDD (Test Driven Development) is a software development process that is based on repeating a short cycle: first, the requirements are transformed in specific test cases, and then the software is improved so that it can pass the new tests. This is different from the approach where the software was developed without proving it can meet all requirements.

Some of the benefits of TDD are:

  • The fact that the programmer has clear targets
  • The code is safer
  • The correct code can be isolated
  • New functionalities can be more easily introduced
  • The tests document the application

The challenges of Junit 4

Junit 4, which appeared in 2006, has a simple and monolithic architecture. The entire functionality is concentrated in a single JAR file. Despite its apparent simplicity, there were a couple of problems early on, which became worse as time went by.

JUnit 5 – new approach, new functionalities.jpg


The fact that the existent API is not flexible forced the IDEs and tools which used Junit to be completely linked with it. It was necessary to access the internal implementation of JUNit or even use reflection to obtain the nece4sary information.

Therefore, because the same JAR file was used by everyone and IDEs were strongly linked to it, the ways in which it could evolve were seriously hindered. The changing of a variable or a private method could impact those who used it externally. A new API, designed for these types of tools and a new architecture were necessary to ensure its further evolution.

A new modular approach

A new approach, a modular one, was needed to allow Junit to evolve. It required:

  • An API for writing tests, dedicated to developers first of all
  • A mechanism for discovering and running tests
  • An API which allows an easy interaction with IDEs and test running tools

As a result the Junit 5 architecture has 3 modules:

  • Junit Platform
  • Junit Jupiter
  • Junit Vintage

Junit Platform is used for launching the testing framework on a Java virtual machine. It also offers an API for launching test from the console, IDEs or other tools.

JUnit Jupiter is a combination between the new programming model and the extension model for writing tests and extensions in Junit 5.

Junit Vintage offers a testing engine to run Junit 3 and Junit 4 test on the new platform, ensuring the necessary compatibility.

Interested in JUnit? Check out our trainings.

Catalin Tudose
Java and Web Technologies Expert

Share the knowledge

Luxoft Warsaw - Warsaw Spire, plac Europejski 1, 00-844 Warszawa
Dimitrie Pompeiu nr 5-7 , building C, Et. 5, sect 2, Bucharest, 014459

Contact phone:

021 371 4858
Luxoft Poland Wroclaw - Silver Tower pl. Konstytucji 3-go Maja 3 50-048 Wroclaw
Aleja Generała Tadeusza Bora-Komorowskiego 25, Quattro Business Park Five, 31-476 Kraków, Poland

Contact phone:

+48 122110650
Success
Thank you.
Your request has been received.