Parallel Execution of Classes in TestNG

Test Case: 1

package testng;

import org.testng.annotations.Test;

public class ParallelExecutionCase1 
{
	@Test
	public void TestCase1()
	{
		System.out.println("Executing 1st Test Case ---" + getClass().getSimpleName()+ " with Thread Id:- " + Thread.currentThread().getId());
	}
	@Test
	public void TestCase2()
	{
		System.out.println("Executing 2nd Test Case ---" + getClass().getSimpleName()+ " with Thread Id:- " + Thread.currentThread().getId());
	}

}

Test Case: 2

package testng;

import org.testng.annotations.Test;

public class ParallelExecutionCase2 
{
	@Test
	public void TestCase3()
	{
		System.out.println("Executing 3rd Test Case ---" + getClass().getSimpleName()+ " with Thread Id:- " + Thread.currentThread().getId());
	}
	@Test
	public void TestCase4()
	{
		System.out.println("Executing 4th Test Case ---" + getClass().getSimpleName()+ " with Thread Id:- " + Thread.currentThread().getId());
	}


}

testng.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel Test Suite" parallel="classes" thread-count="2">
  <test name="Parallel Execution">
    <classes>
      <class name="testng.ParallelExecutionCase1"/>
      <class name="testng.ParallelExecutionCase2"/>
    </classes>
  </test>
</suite>

 

Leave a Reply

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