Was it helpful?

Question

How will you run a prerequisite method and post condition method for every test in TestNG?

TestNGFrameworkJava Programming

We can run a prerequisite method and post condition method for every test in TestNG with the help of @BeforeMethod and @AfterMethod annotations.

Example

@BeforeMethod
public void prerequisite(){
   System.out.println("Run before every tests");
}
@AfterMethod
public void postcondition(){
   System.out.println("Run after every tests ");
}
@Test
public void loanPay(){
   System.out.println("Loan pay is successful");
}

In the Java class file, the prerequisite() method with @BeforeMethod will be executed which is known as the precondition for every test method. Then loanPay() will be executed and finally the postcondition() method with @AfterMethod will run.

raja
Published on 11-Jun-2020 16:17:26
Advertisements
Was it helpful?
Not affiliated with Tutorialspoint
scroll top