According to this blog what I study for the Junit 4 and Junit5:
JUnit 5 is a powerful and flexible update to the JUnit framework, providing various improvements and new capabilities to organize and describe test cases and to help understand test results. Upgrade to JUnit 5 is quick and easy: Just update your project dependencies and start using the new functionality.
JUnit 4 bundles everything into a single JAR file.
JUnit 5 consists of three sub-projects, namely JUnit Platform, JUnit Jupiter, and JUnit Vintage.
1. JUnit platform
It defines TestEngine’s API for developing new testing frameworks that run on the platform.
It has all the new JUnit annotations and TestEngine implementations to run tests written with those annotations.
Support for running tests written by JUnit 3 and JUnit 4 on the JUnit 5 platform.
But here are four strong reasons to start writing new test cases with JUnit 5:
JUnit 5 takes advantage of features from Java 8 or later, such as lambda functions, to make tests more powerful and easier to maintain.
JUnit 5 adds some very useful new capabilities for describing, organizing, and executing tests. For example, tests get better display names and can be organized hierarchically.
JUnit 5 is organized into multiple libraries, so import only the functionality you need into your project. With build systems like Maven and Gradle, it’s easy to include the right libraries.
JUnit 5 can use multiple extensions at the same time, something that JUnit 4 cannot do (you can only use one runner at a time). This means that you can easily combine Spring extensions with other extensions, such as your own custom extensions.
The JUnit 5 tests look pretty much the same as the JUnit 4 tests, but there are a few differences you should be aware of.
The import. JUnit 5 uses the new org.junit.jupiter package. . For example, org. Junit. Junit Test into org. Junit. Jupiter. API. Test.
Annotation. The @Test annotation no longer has arguments; each argument is moved to a function.
Assertions. JUnit Assertions 5 now in org. JUnit. Jupiter. API. Assertions. Most common assertions, such as assertEquals() and assertNotNull(), look the same as before, but with a few differences.
The hypothesis. Assumption has been moved to org. Junit. Jupiter. API. Assumptions.
In summary, JUnit 5’s tests are more powerful and easier to maintain. In addition, JUnit 5 offers many useful new features. Only the features you use will be imported, you can use multiple extensions, and you can even create your own custom extensions. Together with the new features, these changes provide a powerful and flexible update to the JUnit framework.
From the blog haorusong by and used with permission of the author. All other rights reserved by the author.