尝试使用 Surefire 从 Maven 启动并行 TestNG 测试
Trying to launch parallel TestNG tests from Maven using Surefire
我正在尝试使用 Surefire 从 Maven 启动并行 TestNG 测试,但到目前为止收效甚微。
我的套件有 4 个测试,但 Maven 到目前为止只是 运行 一次一个地串联测试。只有当一个测试完成后,下一个测试才会开始。
如果您能查看我正在使用的配置,如果您发现任何不妥之处或有任何一般性建议,请告诉我,我将不胜感激。
这是 pom.xml 中 surefire 的配置方式:-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>3</threadCount>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>src/main/MyTestSuite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
这是我的套件文件 (MyTestSuite.xml): -
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="My Custom suite" parallel="classes">
<parameter name="driver.type" value="CHROME"/>
<parameter name="environment" value="DEV"/>
<parameter name="timeout" value="5000"/>
<parameter name="maxAttempts" value="20"/>
<parameter name="logLevel" value="INFO"/>
<parameter name="driver.quit" value="true"/>
<suite-files>
<suite-file path="./Test1.xml"/>
<suite-file path="./Test2.xml"/>
<suite-file path="./Test3.xml"/>
<suite-file path="./Test4.xml"/>
</suite-files>
</suite>
这里是单个套件文件之一的示例 (Test1.xml):-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Suite 1" parallel="classes">
<test verbose="10" name="Test1" annotations="JDK">
<classes>
<class name="com.me.test.Test1" />
</classes>
</test>
</suite>
测试 运行 成功,但是是串联的,不是并行的。欢迎提出任何建议。我的 Cucumber 并行测试 运行 毫无问题,但到目前为止 TestNG 运气不佳。感谢阅读。
您正在使用一套套件。默认情况下,当 TestNG 看到一组套件时,它 运行 按顺序排列它们,除非另有指示。
在您的情况下,您可以通过如下配置 surefire 插件来触发并行套件执行:
先把属性加起来如下
<properties>
<threads>2</threads>
<file>src/test/resources/MyTestSuite.xml</file>
</properties>
然后如下定义surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>${file}</suiteXmlFiles>
<skipTests>false</skipTests>
<properties>
<property>
<name>suitethreadpoolsize</name>
<value>${threads}</value>
</property>
</properties>
</configuration>
</plugin>
您现在可以 运行 使用命令 mvn clean test -Dthreads=1
进行测试
更多关于并行执行和运行不使用套件的并行宁套件,可以参考我的博客post here.
我正在尝试使用 Surefire 从 Maven 启动并行 TestNG 测试,但到目前为止收效甚微。
我的套件有 4 个测试,但 Maven 到目前为止只是 运行 一次一个地串联测试。只有当一个测试完成后,下一个测试才会开始。
如果您能查看我正在使用的配置,如果您发现任何不妥之处或有任何一般性建议,请告诉我,我将不胜感激。
这是 pom.xml 中 surefire 的配置方式:-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>3</threadCount>
<testFailureIgnore>true</testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>src/main/MyTestSuite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
这是我的套件文件 (MyTestSuite.xml): -
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="My Custom suite" parallel="classes">
<parameter name="driver.type" value="CHROME"/>
<parameter name="environment" value="DEV"/>
<parameter name="timeout" value="5000"/>
<parameter name="maxAttempts" value="20"/>
<parameter name="logLevel" value="INFO"/>
<parameter name="driver.quit" value="true"/>
<suite-files>
<suite-file path="./Test1.xml"/>
<suite-file path="./Test2.xml"/>
<suite-file path="./Test3.xml"/>
<suite-file path="./Test4.xml"/>
</suite-files>
</suite>
这里是单个套件文件之一的示例 (Test1.xml):-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Suite 1" parallel="classes">
<test verbose="10" name="Test1" annotations="JDK">
<classes>
<class name="com.me.test.Test1" />
</classes>
</test>
</suite>
测试 运行 成功,但是是串联的,不是并行的。欢迎提出任何建议。我的 Cucumber 并行测试 运行 毫无问题,但到目前为止 TestNG 运气不佳。感谢阅读。
您正在使用一套套件。默认情况下,当 TestNG 看到一组套件时,它 运行 按顺序排列它们,除非另有指示。
在您的情况下,您可以通过如下配置 surefire 插件来触发并行套件执行:
先把属性加起来如下
<properties>
<threads>2</threads>
<file>src/test/resources/MyTestSuite.xml</file>
</properties>
然后如下定义surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>${file}</suiteXmlFiles>
<skipTests>false</skipTests>
<properties>
<property>
<name>suitethreadpoolsize</name>
<value>${threads}</value>
</property>
</properties>
</configuration>
</plugin>
您现在可以 运行 使用命令 mvn clean test -Dthreads=1
更多关于并行执行和运行不使用套件的并行宁套件,可以参考我的博客post here.