How will you run a prerequisite method and post condition method for every test in TestNG?
-
13-09-2020 - |
Question
How will you run a prerequisite method and post condition method for every test in TestNG?
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.
Advertisements
Not affiliated with Tutorialspoint