[testng]- Running groups in Parallel

1,002 views
Skip to first unread message

ndk

unread,
Feb 9, 2011, 3:35:03 PM2/9/11
to testng-users
I am trying to run tests in parallel using TestNG. All I want to do is
run two methods test1() and test2() in two different threads. I am
using TestNG 5.14.3. I have configured TestNG to run my tests in
parallel but they are running sequentially. Is there anything I am
missing here? Here is my code and testng xmls.

public class RunMe {
@Test(groups="customer")
public void test1() {
//..some code
}
@Test(groups="department")
public void test2() {
//..some code
}
}
//testng1.xml
<suite name="customer" parallel="tests" thread-count="5">
<test name="test.run.customer">
<groups>
<run>
<include name="customer"/>
</run>
</groups>
<classes>
<class name="test.run.RunMe"/>
</classes>
</test>
</suite>
testng2.xml is same but just that the group "customer" is replaced by
group "department"

When I do run following tests run sequentially.
java org.testng.TestNG testng1.xml testng2.xml

Would appreciate if someone could point, if I am doing something
wrong.

Thanks,
-Nilesh

Cédric Beust ♔

unread,
Feb 9, 2011, 3:40:13 PM2/9/11
to testng...@googlegroups.com
Use parallel="methods" in your testng.xml.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.




--
Cédric


ndk

unread,
Feb 9, 2011, 3:46:36 PM2/9/11
to testng-users
Hi Cedric,
I already tried parallel="methods" in my xmls but result is the same.
Is there any additional parameters I should use to my commands line
below ?

java org.testng.TestNG testng1.xml testng2.xml

Cédric Beust ♔

unread,
Feb 9, 2011, 4:03:57 PM2/9/11
to testng...@googlegroups.com
Can you print out the thread id in each of your method? If you specify test="methods" in both your testng.xml, they should be running in different threads.

-- 
Cédric

ndk

unread,
Feb 9, 2011, 4:16:46 PM2/9/11
to testng-users
Thread Ids are indeed different. But the groups run one after the
other. For example, I have put a Thread.sleep(5000); in the first
method and the second method runs after that sleep. Shouldn't we
expect test1 and test2 run at the same time?

public class RunMe {
@Test(groups="customer")
public void test1() throws InterruptedException {
Thread t = Thread.currentThread();
System.out.println("Hello there 1st thread");
System.out.println(t.getId()+t.getName());
Thread.sleep(5000);
}
@Test(groups="dept")
public void test2() {
Thread t = Thread.currentThread();
System.out.println("Hello there 2nd thread");
System.out.println(t.getId()+t.getName());

ndk

unread,
Feb 9, 2011, 4:21:08 PM2/9/11
to testng-users
This is the output. Instead of Thread.sleep, I had also tried
t.sleep(5000) which I guess would make sense.
java org.testng.TestNG testng1.xml testng2.xml

[TestNG] Running:
C:\TestNGParallelRuns\testng1.xml

Hello there 1st thread
10pool-2-thread-1

===============================================
customer
Total tests run: 1, Failures: 0, Skips: 0
===============================================

[TestNG] Running:
C:\TestNGParallelRuns\testng2.xml

Hello there 2nd thread
12pool-4-thread-1

===============================================
dept
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Cédric Beust ♔

unread,
Feb 9, 2011, 4:30:20 PM2/9/11
to testng...@googlegroups.com
I'm pretty sure they do run "at the same time", you are just paying too much attention to the output.

For example, add "invocationCount=10" on each of your test methods and you will probably see the outputs of both interleaved.

-- 
Cédric

ndk

unread,
Feb 9, 2011, 4:47:29 PM2/9/11
to testng-users
Added invocationCount=10 to each of the methods. Outputs are still not
interleaved. I also tried with count 20, 30 but still sequential
behavior. Obviously there is something I am missing here.
To explain it further I am trying to write my selenium scripts so that
my two test groups can run in parallel. So eventual goal of my
experiment is to run two browsers at the same time and run tests in
parallel.

Thanks Cedric for helping out.

C:\TestNGParallelRuns\testng1.xml

Hello there 1st thread
Hello there 1st thread
Hello there 1st thread
Hello there 1st thread
Hello there 1st thread
Hello there 1st thread
Hello there 1st thread
Hello there 1st thread
Hello there 1st thread
Hello there 1st thread

===============================================
customer
Total tests run: 10, Failures: 0, Skips: 0
===============================================

[TestNG] Running:
C:\TestNGParallelRuns\testng2.xml

Hello there 2nd thread
Hello there 2nd thread
Hello there 2nd thread
Hello there 2nd thread
Hello there 2nd thread
Hello there 2nd thread
Hello there 2nd thread
Hello there 2nd thread
Hello there 2nd thread
Hello there 2nd thread

===============================================
dept
Total tests run: 10, Failures: 0, Skips: 0
===============================================

ndk

unread,
Feb 10, 2011, 1:54:20 PM2/10/11
to testng-users
Hi Cedric,

I am not sure if you noticed, but I am not running my tests as an ant
task. Thats the only missing piece I could find. Does that matter? I
am running like,
java org.testng.TestNG testng1.xml testng2.xml

and from TestNG documentation it says - java org.testng.TestNG -
suitethreadpoolsize 3 testng1.xml testng2.xml testng3.xml

The corresponding ant task name is suitethreadpoolsize.

Thanks,
-Nilesh

Cédric Beust ♔

unread,
Feb 10, 2011, 2:18:07 PM2/10/11
to testng...@googlegroups.com
Hi Nilesh,

I just found and fixed a bug in this area but it doesn't seem to be related to the problem you're seeing.

With the new jar, things seem to be working for me: I launch TestNG on two different xml files, each with one test class, and I also specify -suitethreadpoolsize:

testng -suitethreadpoolsize 3 src/test/resources/testng-single.yaml src/test/resources/testng-single2.yaml

Each of these test methods prints something, sleeps for 5 seconds then prints something else. The test run does reflect this:

suite1.test1 started
suite2.test2 started
<5 seconds>
<both suites finish>

Please try your example on this new jar file and report back:  http://testng.org/beta

-- 
Cédric

ndk

unread,
Feb 10, 2011, 2:39:51 PM2/10/11
to testng-users
Wow, that works like a charm. Thanks so much Cedric. You made my
day :)
Reply all
Reply to author
Forward
0 new messages