@BeforeEach and @AfterEach Annotation

This lesson demonstrates working of two Lifecycle methods annotated with - @BeforeEach and @AfterEach Annotation.

@Test and Constructor

In Junit 5 for each test, a new instance of test class is created. So, for e.g. if a class has two @Test methods than two instances of test class will be created, one for each test. Thus, the constructor of the test class will be called as many times as there is the number of @Test methods. Let’s look at the demo:-

Get hands-on with 1200+ tech skills courses.