简体   繁体   English

尝试使用Surefire从Maven启动并行的TestNG测试

[英]Trying to launch parallel TestNG tests from Maven using Surefire

I am trying to to launch parallel TestNG tests from Maven using Surefire, but with little success so far. 我正在尝试使用Surefire从Maven启动并行的TestNG测试,但到目前为止收效甚微。

My suite has 4 tests, but Maven is so far just running the tests one at a time, in series. 我的套件有4个测试,但是到目前为止,Maven只是一次连续运行一个测试。 Only when one test finishes does the next one start. 只有当一个测试完成时,下一个测试才开始。

I would be very grateful if you could look at the config I am using and let me know if you spot anything amiss or have any general suggestions. 如果您能查看我正在使用的配置,并让我知道您发现任何不对劲或有任何一般性建议,我将不胜感激。

This is how surefire is configured in pom.xml: - 这是在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>

This is my suite file (MyTestSuite.xml): - 这是我的套件文件(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>

And here is an example of one of the individual suite files (Test1.xml): - 这是单个套件文件(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>

The tests run successfully, but in series, not parallel. 测试成功运行,但是是串行运行,而不是并行运行。 Any suggestions would be most welcome. 任何建议将是最欢迎的。 I have had no problem getting surefire to run my Cucumber tests in parallel, but no luck so far with TestNG. 我毫无疑问可以并行运行Cucumber测试,但是到目前为止,使用TestNG还是没有运气。 Thank you for reading. 感谢您的阅读。

You are working with a suite of suites. 您正在使用套件套件。 By default when TestNG sees a suite of suites, it runs them in sequence unless instructed otherwise. 默认情况下,当TestNG看到套件套件时,除非另有说明,否则它将按顺序运行它们。

In your case, you can trigger parallel suite execution by configuring your surefire plugin as below : 在您的情况下,您可以通过如下配置surefire插件来触发并行套件执行:

First add up properties as below 首先添加以下属性

<properties>
    <threads>2</threads>
    <file>src/test/resources/MyTestSuite.xml</file>
</properties>

and then define the surefire plugin as below: 然后如下定义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>

You can now run your tests using the command mvn clean test -Dthreads=1 现在,您可以使用命令mvn clean test -Dthreads=1运行测试

For more details on parallel execution and running suites in parallel without using a suite of suites, you can refer to my blog post here . 有关并行执行和在不使用套件的情况下并行运行套件的更多详细信息,可以在此处参考我的博客文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用maven surefire插件并行执行testng测试 - how to execute testng tests in parallel using maven surefire plugin 使用Maven Surefire进行并行Cucumber-JVM Selenium网格测试 - Parallel Cucumber-JVM Selenium Grid Tests using Maven Surefire 与 maven surefire 插件并行运行测试 - Running tests in parallel with maven surefire plugin 使用Surefire在jar中执行TestNG / Selenium测试 - Using Surefire to execute TestNG/Selenium tests in a jar Disable parallel execution in maven testng selenium java (using the surefire plugin - it does not run according to the order in the testng.xml) - Disable parallel execution in maven testng selenium java (using the surefire plugin - it does not run according to the order in the testng.xml) Maven surefire在模块中找不到Testng测试 - Maven surefire can't find testng tests in module Maven Surefire 插件未启动 TestNG 套件 XML 文件中定义的测试 - Maven Surefire plugin not starting tests defined in TestNG suite XML file 在并行模式下使用maven-surefire-plugin时如何识别慢速单元测试? - How to identify slow unit tests when using maven-surefire-plugin in parallel mode? Maven Surefire并行测试中跳过测试的非确定性行为 - Non-deterministic behavior of skipped tests in parallel testing on Maven Surefire 未使用Maven的“ surefire”插件运行测试 - Tests not running using the 'surefire' plugin for Maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM