@BeforeTest and @AfterTest
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.
Java Class
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
importorg.testng.annotations.Test;
publicclass TestNGExample {
@BeforeSuite
publicvoid BeforeSuiteSample(){
System.out.println("This Method will Execute before suite");
}
@AfterSuite
publicvoid AfterSuiteSample(){
System.out.println("This Method will Execute After Suite");
}
@BeforeTest
publicvoid BeforeTestSample(){
System.out.println("This Method will Execute Before Test");
}
@AfterTest
publicvoid AfterTestSample(){
System.out.println("This Method will Execute After Test");
}
}
TestNG.xml file
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none">
<testname="Test">
<classes>
<classname="TestNGExample"/>
</classes>
</test><!-- Test -->
</suite><!—Suite -->
Results

@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.
Java Class
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
importorg.testng.annotations.Test;
publicclass TestNGExample {
@BeforeSuite
publicvoid BeforeSuiteSample(){
System.out.println("This Method will Execute before suite");
}
@AfterSuite
publicvoid AfterSuiteSample(){
System.out.println("This Method will Execute After Suite");
}
@BeforeTest
publicvoid BeforeTestSample(){
System.out.println("This Method will Execute Before Test");
}
@AfterTest
publicvoid AfterTestSample(){
System.out.println("This Method will Execute After Test");
}
}
TestNG.xml file
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none">
<testname="Test">
<classes>
<classname="TestNGExample"/>
</classes>
</test><!-- Test -->
</suite><!—Suite -->
Results
Comments
Post a Comment