Junit5 tutorial: Part-1
Junit5 tutorials for beginner.
Junit is the Java’s most popular unit testing library, recently has released a new version 5. JUnit 5 is a combination of several modules from three different sub-projects.
JUnit is an open-source Unit Testing Framework for JAVA. It is useful for Java Developers to write and run unit tests. Erich Gamma and Kent Beck initially develop it.
JUnit 5 is an evolution of JUnit 4, and did some further improves the testing experience. As we are aware Junit5 is the major version release and its aims to adapt java 8 styles of coding and to be more robust and flexible than the previous releases.
Advantages:- Below are the few advancements in this version over older once.
- The entire framework was contained in a single jar library.
- In JUnit 5, we get more granularity and can import only what is necessary.
- JUnit 5 makes good use of Java 8 styles of programming and features.
- JUnit 5 allows multiple runners to work simultaneously.
- The best thing about Junit5 is backward Compatibility for JUnit 4.
Moving from Junit 4 to Junit5:-
In this section let us explore the motivation behind the Junit5.
- Junit4 was developed a decade ago, now context has bit changed and programming style too.
- Junit4 is not compatible with JDK8 and its new functional programming paradigm.
- Junit4 is not modular. A single jar is a dependency for everything.
- Test discovery and execution are tightly coupled in Junit4.
- The most important thing nowadays developer not only want unit testing but also they want integration testing and system testing.
These are few reasons to rewrite junit5 from scratch using java8 and introduced some new features.
Junit5 is modular architecture and the main three components are Platform, Jupiter and vintage.
Let us understand above this three module.
- Platform:- Platform, which serves as a foundation for launching testing frameworks on the JVM. It also provides an API to launch tests from either the console, IDEs, or build tools.
- Jupiter:- Jupiter is the combination of the new programming model and extension model for writing tests and extensions in JUnit 5. The name has been chosen from the 5th planet of our Solar System, which is also the largest one.
- Vintage:- Vintage in general something from the past. Vintage provides a test engine for running JUnit 3 and JUnit 4 based tests on the platform, ensuring the necessary backward compatibility.
As part of this tutorial, we are able to understand what is new Junit5 and what is it. In the next tutorial, we will explore more and we will take some examples.