I got stucked in rather unique problem and I'm sure some of you might have faced similar problem at some point.
So I have total 10 Test classes in my testNg suite and I want them to run in parallel. This is easy but the problem is one of my class lets assume class Test A, not only sets up the test data but also tests some functionality of the application, hence I can not use it under BeforeSuite or BeforeTest annotation. The Test data created via the execution of tests under this class is important for other test classes to run, hence I'm really scratching my head how to implement Class level parallelism in such a way that the parallel run only initiate after the tests under Tests A class finishes it's execution.
Summary
Class Test A
public class TestsA {
@BeforeClass
public setupTestClass(){
-----some code--------
}
@Test
public test1(){
------some code---
}
I want this TestA class to run first and then instantiate other test classes in parallel. Any help regarding this would be really appreciated.
Thanks
I've found the solution for the above problem. All I had to do is to have two different tests configured on my testng.xml suite. 1st test will have only Test class A and the other test will have other test classes having parallelism at class level. Since under 1st test there's only one class, the tests under that class will be executed first. In my case Test Class A which is responsible to test some functionality as well as setup some data. Then the next test of your testng.xml will instantiate the other classes in parallel.
Below is how my testng.xml looks
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test_Suite_Name" verbose="1" parallel="classes" thread-count="4">
<test name="TEST_TESTCLASSA" preserve-order="true">
<parameter name="environment" value="macos"/>
<groups>
<run>
<include name="Smoke"/>
<exclude name="Sanity"/>
<exclude name="Exclude"/>
</run>
</groups>
<classes>
<class name="testpackage.TestClassA"/>
</classes>
</test>
<test name="TEST_OTHER_TESTS" preserve-order="true">
<parameter name="environment" value="macos"/>
<groups>
<run>
<include name="Smoke"/>
<exclude name="Sanity"/>
<exclude name="Exclude"/>
</run>
</groups>
<classes>
<class name="testpackage.TestClassB"/>
<class name ="testpackage.TestClassC"/>
<class name="testpackage.TestClassD"/>
<class name="testpackage.TestClassE"/>
<class name="testpackage.TestClassF"/>
<class name="testpackage.TestClassG"/>
</classes>
</test>
</suite>