@Before and @After Annotations explained

TestNg has five different options for Before and After annotations. Each of them will be explained below.

On a general note the Before and After annotations are used to set variables or configurations before the execution of test methods and clean up after the execution.

Let us see an example of how the @Before and @After annotations are called

We will create a method for each of these Before/After and call them all so we can actually see the order in which they are executed, related to each other and related to @Test methods.

/**
* This annotation will be run before all tests in the suite.
*/
@BeforeSuite
  public void beforeSuite(){
System.out.println(“Before Suite method”);
}
/**
* This annotation will be run after all tests in the
suite. */
@AfterSuite
public void afterSuite(){
System.out.println(“After Suite method”);
}