1
votes

I have a java maven project that I want tested using multithreads. I have the testng.xml in src/test and the maven surefire plugin is configured to used it. Just like this page: http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html

edit: added surefire pom entry

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-surefire-plugin</artifactId>
 <version>2.12.4</version>
 <configuration>
  <suiteXmlFiles>
   <suiteXmlFile>src/test/testng.xml</suiteXmlFile>
  </suiteXmlFiles>
 </configuration>
</plugin>

I am using surefire 2.12.4.

This is my testng.xml file

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
 <suite name="Testng" parallel="methods" thread-count="3">
  <test name="all" annotations="JDK5">
    <packages>
        <package name="my.package.*"/>
    </packages>
  </test>
</suite>

Inside several test methods I have a print statement:

System.out.println(Thread.currentThread().getName());

That always has the same output every run (pool-1-thread-1). If testng was running parallel then there would be different threads running.

My questions are: why is testng not running multithreaded? and is there a better way to check if testng is running multithreaded?

edit: classes or methods

When I run with threads each test class seems to run in it's own thread, but not each method. In the testng.xml I set parallel="methods" so it should do it per method. Can it not do per method?

2
It works for me with testng 6.8 and maven surefire plugin 2.12.4 as well as 2.13, the tests run in parallel in different threads. Can you detail the surefire part of your pom ..niharika_neo
I am using testng6.8 tooclurect
Well, I still see the same behavior. Are you sure ur xml is being invoked? Are the tests that are running are the ones that you specified in ur xml?niharika_neo
Yes they are running. I even used the testng plugin for eclipse to run the suite directly. Still no different threads.clurect
@niharika_neo how are you showing that testng is actually spawning more threads?clurect

2 Answers

0
votes

I found the answer, I wasn't giving it enough threads. Since my project has many tests testng would not make new threads per method. I changed it to 10 threads and that fixed it.

0
votes

TestNG will not be running in parallel in this case. You need to define ThreadLocal to define different browsers in threads. Use: ThreadLocal, and define the browsers in different instances. You will be getting different browser ID's in this case..