TestNG – 9 || Let’s move deep into the Test Suites.

Test Suites widely used to organize and execute test cases from multiple class files. It also helps to create various test sets using these classes and methods.

Multiple Test Sets in TestNG Suite
Multiple Test Sets in TestNG Suite

To understand this, we need to create different class files. Let’s create below class files using specific methods.

  • LaunchAndLogin.java
    • launchBrowser()
    • launchURL()
    • login()
  • MyOrders.java
    • viewOrders()
    • placeOrder()
  • MyProfile.java
    • editProfile()
    • saveProfile()
    • viewProfile()
  • LogoutAndClose.java
    • logout()
    • closeBrowser()

Test Suites using multiple Classes

LaunchAndLogin.java

package testSuitePackage;
import org.testng.annotations.Test;

/**
 * @author ashok.kumar
 */
public class LaunchAndLogin 
{
	@Test
	public void launchBrowser()
	{
		System.out.println("Browser launched successfully.");
	}
	
	@Test
	public void launchURL()
	{
		System.out.println("WebSite launched successfully.");
	}
	
	@Test
	public void login()
	{
		System.out.println("User Logged-In using valid credentials.");
	}
}

MyOrders.java

package testSuitePackage;
import org.testng.annotations.Test;

/**
 * @author ashok.kumar
 */
public class MyOrders {
	
	@Test
	public void viewOrders()
	{
		System.out.println("My Orders page get opened.");
	}
	
	@Test (dependsOnMethods="viewOrders")
	public void placeOrder()
	{
		System.out.println("New item added to the My Orders.");
	}
}

MyProfile.java

package testSuitePackage;
import org.testng.annotations.Test;

/**
 * @author ashok.kumar
 */
public class MyProfile {
	
	@Test
	public void editProfile()
	{
		System.out.println("Changes updated in the Profile.");
	}
	
	@Test
	public void saveProfile()
	{
		System.out.println("Profile saved successully.");
	}

	@Test
	public void viewProfile()
	{
		System.out.println("Profile page get opened.");
	}
}

LogoutAndClose.java

package testSuitePackage;
import org.testng.annotations.Test;

/**
 * @author ashok.kumar
 */
public class LogoutAndClose 
{
	
	@Test
	public void logout()
	{
		System.out.println("User logged out successfully.");
	}

	@Test (dependsOnMethods="logout")
	public void closeBrowser()
	{
		System.out.println("Browser Closed.");
	}
}

Updated_TestSuite.xml

<?xml version="1.0" encoding="UTF-8"?>
<suite name="UpdatedSuiteExample" parallel="false">
	
	 <test name="AlphaTestCases">
	    <classes>
	      <class name="testSuitePackage.LaunchAndLogin"/>
	       <class name="testSuitePackage.MyOrders"/>
	        <class name="testSuitePackage.MyProfile"/>
	         <class name="testSuitePackage.LogoutAndClose"/>
	    </classes>
	  </test> 
</suite> <!-- Suite -->

Result Analysis

Result Analysis

index.html (chronological order)

index.html (chronological order)

Creating Multiple Test Sets using Multiple Classes

Suppose, as per requirement we have to create different Test Sets for Alpha Round, Smoke Test and UAT using all the four classes and methods. We can distribute the test methods as mentioned below table:

Test SetAlphaTestCasesSmokeTestCasesUATTestCases
Test Case Count1075
Class NamesLaunchAndLogin
MyOrders
MyProfile
LogOutAndClose
LaunchAndLogin
MyOrders
MyProfile
LogOutAndClose
LaunchAndLogin
MyOrders
MyProfile
Method NameslaunchBrowser()
launchURL()
login()
placeOrder()
viewOrders()
editProfile()
saveProfile()
viewProfile()
logout()
closeBrowser()
launchBrowser()
launchURL()
login()
viewOrders()
editProfile()
saveProfile()
logout()
launchBrowser()
launchURL()
login()
viewOrders()
viewProfile()

To Create these Test Sets we have to modify our XML file as mentioned below:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="UpdatedSuiteExample" parallel="false">
	
	 <test name="AlphaTestCases">
	    <classes>
	      <class name="testSuitePackage.LaunchAndLogin"/>
	       <class name="testSuitePackage.MyOrders"/>
	        <class name="testSuitePackage.MyProfile"/>
	         <class name="testSuitePackage.LogoutAndClose"/>
	    </classes>
	  </test> 
	  
	  <test name="SmokeTestCases">
	    <classes>
	      <class name="testSuitePackage.LaunchAndLogin"/>
	      
	       <class name="testSuitePackage.MyOrders">
	       <methods>
	       		<include name="viewOrders"></include>
	       </methods>
	       </class>
	       
	        <class name="testSuitePackage.MyProfile">
	        <methods>
	        	<include name="editProfile"></include>
	        	<include name="saveProfile"></include>
	        </methods>
	        </class>
	        
	         <class name="testSuitePackage.LogoutAndClose">
	         <methods>
	         	<include name="logout"></include>
	         </methods>
	         </class>
	    </classes>
	  </test> 
	  
	  	 <test name="UATTestCases">
	    <classes>
	      <class name="testSuitePackage.LaunchAndLogin"/>
	      
	       <class name="testSuitePackage.MyOrders">
	       <methods>
	       		<include name="viewOrders"></include>
	       </methods>
	       </class>
	       
	        <class name="testSuitePackage.MyProfile">
	        <methods>
	        	<include name="viewProfile"></include>
	        </methods>
	        </class>
	    </classes>
	  </test> 
	  
</suite> <!-- Suite -->

Result Analysis

UpdatedSuiteExample
index.html (Tests)
index.html (Tests)
emailable-report.html Test cases distribution
emailable-report.html

Related Links:

Java Basics:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:

Excel:


189total visits,7visits today

Leave a Reply

Your email address will not be published. Required fields are marked *