简体   繁体   中英

How to run TestNG tests in parallel JVM process (not threads)

Is it possible to run tests using TestNG framework in two different java processes (JVM)? By default TestNG creates one process and all parallel tests run in separate threads inside it. And I need to wrap all static content inside ThreadLocal<> to make it Thread Safe. But if there is a way to run tests in two different processes I can leave everything as it is. I don't want to worry about Thread Safety.

TestNG not able to run tests in multiple processes. However, at least maven (I hope gradle too) has a plugin for do this job.

See, how maven surefire plugin solves this: https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html .

You may use this config example (add this to pom.xml, build->plugins section):

<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                            <forkCount>2</forkCount>
                            <reuseForks>false</reuseForks>
                            <reportsDirectory>target/surefire-reports-${surefire.forkNumber}</reportsDirectory>
                            <suiteXmlFiles>
                                    <suiteXmlFile>src/test/resources/Suite1.xml</suiteXmlFile>
                                    <suiteXmlFile>src/test/resources/Suite2.xml</suiteXmlFile>
                            </suiteXmlFiles>
                    </configuration>
            </plugin>

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