JUnit 5 – new approach, new functionalities. Part 2
JUnit 5 – new approach, new functionalities. Part 2
In the second part of our article on JUnit 5 – new approach, new functionalities we look at how to make the transition to JUunit 5. Happy reading.
24 Jul 2019
1540
Other articles
How to incrementally migrate the data from RDBMS to Hadoop using Sqoop Incremental Last Modified technique?
How to implement Slowly Changing Dimensions(SCD) Type 2 in Spark?
How to incrementally migrate the data from RDBMS to Hadoop using Sqoop Incremental Append technique?
Why MongoDB don't fetch all the matching documents for the query fired
How to solve the issue of full disk utilization in HDFS Namenode
Can We Use HDFS as Back-up Storage?
How to do Indexing in MongoDB with Elastic Search? Part 1
How to do Indexing in MongoDB with Elastic Search? Part 2
How to store data on browser using NoSQL IndexedDB?
How to Apply MBTI in HR: Motivation for every day. Groups of People & their Motivations
The step towards JUnit 5
In order to use Junit 5 in a Java project, the following dependencies must be added to the Maven configuration:

Below are the most important differences between Junit 4 and Junit 5:
Architecture
Java versions necessary for running
Annotations
First Junit 5 test
Unlike Junit 4, the test class and test methods can be package private. A simulated test looks like this:

A few remarks about the test above:
Java and Web Technologies Expert
In order to use Junit 5 in a Java project, the following dependencies must be added to the Maven configuration:

Below are the most important differences between Junit 4 and Junit 5:
Architecture
JUnit 4 | JUnit 5 |
Monolithic |
Junit Platform Junit Jupiter Junit Vintage |
Java versions necessary for running
JUnit 4 | JUnit 5 |
At least Java 5 | At least Java 8 |
Annotations
JUnit 4 | JUnit 5 |
@BeforeClass, @AfterClass
@Before, @After @Ignore @Category |
@BeforeAll, @AfterAll
@BeforeEach, @AfterEach @Disable @Tag |
First Junit 5 test
Unlike Junit 4, the test class and test methods can be package private. A simulated test looks like this:

A few remarks about the test above:
- The method annotated with @BeforeAll will be executed once, before the tests are running.
- The method annotated with @BeforeEach will be executed every time, before a test is ran.
- The methods annotated with @Test will be executed one by one, in order to check functionality.
- The method annotated with @AfterEach will be executed every time after running a test.
- The method annotated with @AfterAll will be executed once, after running all the tests.
Interested in JUnit? Check out our trainings.
Catalin TudoseJava and Web Technologies Expert