Test Suite in TestNG:-
The test suite is used to execute more than one test class using a single XML file.
Test Suite always will be defined by an XML file that contains multiple test classes using XML tag.
Test Suite always will be defined by an XML file that contains multiple test classes using XML tag.
First Create two different Test Case Classes
package scs;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
public class Test1 {
@BeforeClass
public void bclass(){
System.out.println("Before Class1");
}
@AfterClass
public void aclass(){
System.out.println("After Class1");
}
@BeforeSuite
public void bsclass(){
System.out.println("Before SUIT1");
}
@AfterSuite
public void asclass(){
System.out.println("After Suit1");
}
@Test
public void f() {
System.out.println("Test Class1");
}
@BeforeTest
public void beforeTest() {
System.out.println("Before Test");
}
@AfterTest
public void afterTest() {
System.out.println("After Test");
}
}
Create another class Test2
package scs;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class Test2 {
@Test
public void f() {
System.out.println("Test Class2");
}
@BeforeTest
public void beforeTest() {
System.out.println("Before Test CLASS2");
}
@AfterTest
public void afterTest() {
System.out.println("After Test Class2");
}
}
Syntax of testsuite.xml
<?xml version = "1.0" encoding = "UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name = "Suite1"> <test name = "exampletest1"> <classes> <class name = "Test1" /> </classes> </test> <test name = "exampletest2"> <classes> <class name = "Test2" /> </classes> </test>
@BeforeSuite and @AfterSuite Annotation can be defined in the source code of class which will be executed before suite execution and after suite execution for a particular class.
Post a Comment
POST Answer of Questions and ASK to Doubt