|
Answer» The order of execution of these annotations is as shown below: | @Before | @After | @BeforeClass | @AfterClass |
|---|
| Methods annotated with @Before are executed before each test case. | Methods annotated with @After are executed after each test case. | Methods annotated with @BeforeClass are executed once before the start of all the test cases. | Methods annotated with @AfterClass are executed once all the tests have completed their execution. | | This is used for preparing the test environment like to read inputs, INITIALISE the variables etc. | This is used for cleaning up the test environment like deleting the temporary data, restoring the value of variables to default. This helps in saving memory. | This is used for PERFORMING time-intensive set-up activities like connecting to any resource that is common across all tests. Methods annotated with this API needs to be defined as static methods for WORKING with JUnit. | This is used for performing time-intensive cleanup activities like DISCONNECTING from a resource that is common across all tests. Methods annotated with this annotation has to be defined as static methods for it to work with JUnit. |
|