C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
TestNG @AfterTest annotation@AfterTest: The test method under the @AfterTest annotated method is executed after the execution of all the test methods of the available classes which are kept inside the Let's understand through an example. First case: When @AfterTest annotated method exists at the end. Step 1: Open the Eclipse. Step 2: We create two java projects. Suppose we create a project of Deposits which contains two modules Fixed Deposits and Recurring Deposits. Fixed_Deposit.java
package com.TheDeveloperBlog;
import org.testng.annotations.Test;
public class Fixed_deposit
{
@Test
public void fixed_deposit()
{
System.out.println("Fixed Deposit");
}
@Test
public void roi()
{
System.out.println("Rate of Interest");
}
}
Recurring_Deposit.java
package com.TheDeveloperBlog;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
public class Recurring_deposit
{
@Test
public void recurring_deposit()
{
System.out.println("Recurring Deposit");
}
@AfterTest
public void after_test()
{
System.out.println("After test execution..");}}
In the above case, we use @AfterTest annotation in Recurring_Deposit, which means that the test annotated method, i.e., after_test() will be executed only when all the test methods of Recurring_Deposit class are executed. testng.xml Output
Second case: When @AfterTest annotated method exists in the beginning of a class file. Recurring_deposit.java
package com.TheDeveloperBlog;
mport org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
public class Recurring_deposit
{
@AfterTest
public void after_test()
{
System.out.println("After test execution..");
}
@Test
public void recurring_deposit()
{
System.out.println("Recurring Deposit");
}
}
In the above code, we place the @AfterTest annotated method in the beginning. Output
We got the same output as in the first case, so we conclude that @AfterTest annotated method can be placed anywhere in the class file. The @AfterTest annotated method run after the execution of all the test methods present in the classes which are kept inside the Note: Once the execution is completed, there is a requirement to remove the cookies, delete the process or close the connection, so @AfterTest annotated method is used for this purpose.
Next TopicTestNG Annotations
|