如何在并行JVM进程(而不是线程)中运行TestNG测试



是否可以在两个不同的java进程(JVM(中使用TestNG框架运行测试?默认情况下,TestNG创建一个进程,所有并行测试都在其中的单独线程中运行。我需要将所有静态内容封装在ThreadLocal<gt;以确保线程安全。但是,如果有一种方法可以在两个不同的进程中运行测试,我可以让一切保持原样。我不想担心线程安全。

TestNG无法在多个进程中运行测试。不过,至少maven(我也希望gradle(有一个插件可以完成这项工作。

看,maven surefire插件如何解决这个问题:https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html.

您可以使用以下配置示例(将其添加到pom.xml,build->plugins部分(:

<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>

最新更新