Suite

A suite is represented by one XML file. It can contain one or more tests and is defined by the <suite> tag.<suite> is the root tag of your testng.xml.

List of Attributes for <suite> tag

Name: Name of the Suite, It is mandatory.

Verbose:test results log details in the Eclipse IDE -> 'console'

Parallel: Whether TestNG should run different threads to run this suite.

Thread-Count: allows you to specify how many threads should be allocated for this execution.

Time-out:The maximum number of milliseconds this test should take

Let’s create java class

import org.testng.annotations.Test;
publicclass groupexample {
@Test(groups = { "functest", "exculdegroup" })
publicvoid testMethod1() {
System.out.println("This is testMethod1");
}
@Test(groups = {"exculdegroup"} )
publicvoid testMethod2() {
System.out.println("This is testMethod2");
}
@Test(groups = { "functest" })
publicvoid testMethod3() {
System.out.println("This is testMethod3");
}
}

TestNG.xml file

<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none" verbose ="1" timeOut ="1000">
<testname="Test1">
<classes>
<classname="groupexample"/>
</classes>
</test><!-- Test -->
</suite><!-- Suite -->

Note: All Attribute values should give in double quote(“”)else it will throw an exceptions
Another example specify package names instead of class names in TestNG.xml

Lets create java class

package testngexp;// package name
import org.testng.annotations.Test;
publicclass packagesuiteexp {
@Test(groups = { "functest", "exculdegroup" })
publicvoid testMethod1() {
System.out.println("This is testMethod1");
}
@Test(groups = {"exculdegroup"} )
publicvoid testMethod2() {
System.out.println("This is testMethod2");
}
@Test(groups = { "functest" })
publicvoid testMethod3() throws InterruptedException {
System.out.println("This is testMethod3");
}
}

TestNG.xml file

<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEsuiteSYSTEM"http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="none"verbose="1"timeOut="1000">
<testname="Test1">
<packages>
<packagename="testngexp"/> <!—-Package Name -->
</packages>
</test><!-- Test -->
</suite><!-- Suite -->

Results

image

Parallel Attribute
Parallel attribute on the <suite> tag can take one of the following values.

parallel="methods": TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified.

parallel="tests": TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests.

parallel="classes": TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread.

parallel="instances": TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.
Ex:
<suite name="Suite" parallel="none" thread-count="5" verbose ="1" timeOut ="1000">
<suite name="Suite" parallel="methods" thread-count="5" verbose ="1" timeOut ="1000">
<suite name="Suite" parallel="tests" thread-count="5" verbose ="1" timeOut ="1000">
<suite name="Suite" parallel="classes" thread-count="5" verbose ="1" timeOut ="1000">

<suite name="Suite" parallel="instances" thread-count="5" verbose ="1" timeOut ="1000">


Note:
parallel="none" means no parallel execution tests/classes/packages will run in same thread.

Comments