title: Running test classes in parallel with @Factory in TestNG
body: <p>There are 5 test classes in total. Each of them are initialized using @Factory(dataprovider = "data"). What I want to achieve is, the test methods in each test class should run in parallel with the dataprovider instance. Also, the test classes should be running in parallel. </p>
  
  <p>Something like the following. TestClass1 should be running the dataprovider instances in parallel. So, all the methods of test class TestClass1 will be running in parallel for the dataprovider instances.</p>
  
  <p>Also, like TestClass1, there are 2 other test classes. I am expecting the same behaviour from them, and all 3 test classes running in parallel.</p>
  
  <p>With the arrangement of test classes and parameters in the <strong>testng.xml</strong> giving </p>
  
  <blockquote>
    <p><strong>data-provider-thread-count="10" parallel="instances" thread-count="5""</strong> </p>
  </blockquote>
  
  <p>at suite level and at test level,</p>
  
  <blockquote>
    <p><strong>parallel="instances" thread-count="5"</strong></p>
  </blockquote>
  
  <p>the observed behaviour is that, TestClass1 instances created by the dataprovider instances are running in parallel. TestClass2 and TestClass3 have not started execution. Soon after TestClass1 ends, TestClass2 starts execution in same fashion as TestClass1, followed by TestClass3.</p>
  
  <p>What change do I need to make to achieve the intended behaviour.</p>
  
  <p>Thanks, in advance.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  import org.testng.Assert;
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Factory;
  import org.testng.annotations.Listeners;
  import org.testng.annotations.Test;
  import org.testng.reporters.EmailableReporter2;
  
  @Listeners({ TestExecutionListener.class, EmailableReporter2.class })
  public class TestClass {
  
      private int value;
  
      @Factory(dataProvider = "data", dataProviderClass = TestClass.class)
      public TestClass(final int value) {
          this.value = value;
      }
  
      @Test(alwaysRun = true)
      public void testOdd() {
          Assert.assertTrue(value % 2 != 0);
      }
  
      @Test(alwaysRun = true)
      public void testEven() {
          Assert.assertTrue(value % 2 == 0);
      }
  
      @DataProvider(name = "data")
      public static Iterator&lt;Object[]&gt; data() {
  
          List&lt;Object[]&gt; list = new ArrayList&lt;&gt;();
          for (int i = 0; i &lt; 2; i++) {
              list.add(new Object[] { i });
          }
          return list.iterator();
      }
  }
  </code></pre>
  
  <p>testng.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"&gt;
  &lt;suite name="mobile rc automation suite"
      data-provider-thread-count="10" parallel="instances" thread-count="5"&gt;
  
      &lt;test name="test_1" parallel="instances"
          thread-count="5"&gt;
          &lt;classes&gt;
              &lt;class name="com.test.TestClass1" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
      &lt;test name="test_2" parallel="instances"
          thread-count="5"&gt;
          &lt;classes&gt;
              &lt;class name="com.test.TestClass2" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
      &lt;test name="test_3" parallel="instances"
          thread-count="5"&gt;
          &lt;classes&gt;
              &lt;class name="com.test.TestClass3" /&gt;
          &lt;/classes&gt;
      &lt;/test&gt;
  
  &lt;/suite&gt;
  </code></pre>