简体   繁体   中英

how to execute testng tests in parallel using maven surefire plugin

I am trying to execute Testng tests in parallel using maven surefire plugin.

Please find below the configuration I am using:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
    <skipTests>${skipTests}</skipTests>
    <suiteXmlFiles>
        <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
    </suiteXmlFiles>
    <parallel>tests</parallel>
    <threadCount>5</threadCount>
    <systemProperties>
        <property>
            <name>testData</name>
            <value>${testData}</value>
        </property>
        <property>
            <name>testDataDelimiter</name>
            <value>${testDataDelimiter}</value>
        </property>
    </systemProperties>
    </configuration>
</plugin>

With this configuration I can see only one thread getting started for the execution. Could someone please suggest me the solution for executing the testng tests in parallel.

The most obvious one is by using the parallel parameter. The possible values depend on the test provider used. For JUnit 4.7 and onwards, this may be methods, classes, both, suites, suitesAndClasses, suitesAndMethods, classesAndMethods or all. As a prerequisite in JUnit tests, the JUnit runner should extend org.junit.runners.ParentRunner. If no runner is specified through the annotation @org.junit.runner.RunWith, the prerequisite is accomplished.

The both value has been deprecated since maven-surefire-plugin:2.1.6.

The extension of the parallelism is configured using the following parameters. The parameter useUnlimitedThreads allows for an unlimited number of threads. Unless useUnlimitedThreads=true, the parameter threadCount can be used with the optional parameter perCoreThreadCount=true (true by default). The parameters useUnlimitedThreads and threadCount are to be interpreted in the context of the value specified for the parallel parameter.

I recommend setting useUnlimitedThreads to false, and instead, experimenting with threadCount . Start with something like 10 and work your way up until you find an acceptable thread count that doesn't strain your CPU too much.

I took this directly from the TestNG Surefire documentation as a starting point:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M1</version>
        <configuration>
          <properties>
            <property>
              <name>parallel</name>
              <value>methods</value>
            </property>
            <property>
              <name>dataproviderthreadcount</name>
              <value>30</value>
            </property>
          </properties>
        </configuration>
</plugin>

Note that you need the dataproviderthreadcount property and the parallel property set to methods in order to execute test methods in parallel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM