@Before and @After not supported in JUnit5, and now we have @BeforeEach and @AfterEach to maintain the same functionality from Junit 4.
From the Documentation:
@AfterEach : indicates that the annotated method should be executed after each @Test , @RepeatedTest , @ParameterizedTest or @TestFactory in the current class; similar to JUnit 4s @After . Such methods are inherited if they are not overridden.
@AfterEach public void initCafe() { System.out.println("Test Completed"); }
@BeforeEach : indicates that the annotated method must be executed before each @Test , @RepeatedTest , @ParameterizedTest or @TestFactory in the current class; similar to JUnit 4s @Before . Such methods are inherited if they are not overridden.
@BeforeEach public void initCafe() { cafe = new Cafe(); }
Read more about annotations here .
source share