@Before and @After
@Before
This annotation is used with a method.
Method annotated with @Before annotation is executed before each and every test case method.
This annotation is specifically used to initialise required members in a init or setup kind method.
Example:
@Before
public void init(){
/* write your common initialization code here, which need to execute before each test case execution */
}
@After
This annotation is used with a method.
Method annotated with @After annotation is executed after each and every test cased defined in a class.
This annotation is used specifically to call a method having specific releasing resources related task.
Method annotated with this annotation executed regardless of the test method throws exeception or not.
Example:
@After
public void finish(){
/* write your common resource release related code here, which need to execute after each test case execution */
}