JUnit 5 – usage and first test
4. Making the step to JUnit 5
In order to be able to use JUnit 5 in a Java project, the following dependencies must be added to the Maven configuration:
![Making the step to JUnit 5.png Making the step to JUnit 5.png](/upload/medialibrary/27d/Making the step to JUnit 5.png)
The following differences are to be observed between JUnit 4 and JUnit 5:
![JUnit 4_JUnit 5_architecture.png JUnit 4_JUnit 5_architecture.png](/upload/medialibrary/3d6/JUnit 4_JUnit 5_architecture.png)
5. First JUnit 5 test
Unlike in JUnit 4, the test class and the test methods can be package private. This is how a simple test will look like:
Remarks on the test above:
- The method annotated with @BeforeAll will be executed once, before running the tests.
- The method annotated with @BeforeEach will be executed each time before running each test.
- The method annotated with @Test will be executed in order to verify the functionality.
- The method annotated with @AfterEach will be executed each time after running each test.
- The method annotated with @AfterAll will be executed once, after running all tests.