Thursday, December 10, 2015

TestNG Parallel Execution

  • Methods: This will run the parallel tests on all @Test methods in TestNG.
  • Tests: All the test cases present inside the <test> tag will run with this value.
  • Classes: All the test cases present inside the classes that exist in the XML will run in parallel.

package com.parallel;
import org.testng.annotations.Test;

public class TestParallelOne {

    @Test
    public void testCaseOne() {
        //Printing Id of the thread on using which test method got executed
        System.out.println("Test Case One with Thread Id:- "
                + Thread.currentThread().getId());
    }

    @Test
    public void testCaseTwo() {
        ////Printing Id of the thread on using which test method got executed
        System.out.println("Test Case two with Thread Id:- "
                + Thread.currentThread().getId());
    }
}

Running test methods parallelly in TestNG using Selenium
http://testng.org/testng-1.0.dtd">
<suite name="Parallel test suite" parallel="methods" thread-count="2">
  <test name="Regression 1">
    <classes>
      <class name="com.parallel.TestParallelOne"/>
    </classes>
  </test>
</suite>

Running tests parallelly in TestNG using Selenium

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name = "Parallel Testing Suite" parallel = "tests" thread-count = "2">
   <test name = "Parallel Tests1">
      <classes>
        <class name="com.parallel.TestParallelOne"/>
      </classes>
   </test>
   <test name = "Parallel Tests2">
      <classes>
         <class name="com.parallel.TestParallelOne"/>
      </classes>
   </test>
</suite>
 Running test classes parallelly in TestNG using Selenium
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name = "Parallel Testing Suite">
   <test name = "Parallel Tests" parallel = "classes" thread-count = "2">
      <classes>
         <class name="com.parallel.TestParallelOne"/>
         <class name="com.parallel.TestParallelOne"/>
      </classes>
   </test>
</suite>
   
 

No comments:

Post a Comment