我试图使用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 . 谢谢你的阅读 .
1 回答
您正在使用套房套房 . 默认情况下,当TestNG看到一套套件时,它会按顺序运行它们,除非另有说明 .
在您的情况下,您可以通过配置surefire插件来触发并行套件执行,如下所示:
首先添加属性如下
然后定义surefire插件,如下所示:
您现在可以使用命令
mvn clean test -Dthreads=1
运行测试有关并行执行和并行运行套件而不使用套件套件的更多详细信息,请参阅我的博客文章here .