Tuesday, 4 August 2015

Parallel Execution of Classes in TestNG

package com.parallel;

import org.testng.annotations.Test;

public class TestParallelClassOne {

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

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

}


---------------------------

package com.parallel;

import org.testng.annotations.Test;

public class TestParallelClassTwo {

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

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

}

--------------------------------

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test suite" parallel="classes" thread-count="2">
  <test name="Test 1">
    <classes>
      <class name="com.parallel.TestParallelClassOne"/>
      <class name="com.parallel.TestParallelClassTwo"/>
    </classes>
  </test>
</suite>

No comments:

Post a Comment