繁体   English   中英

尝试使用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运行测试

有关并行执行和在不使用套件的情况下并行运行套件的更多详细信息,可以在此处参考我的博客文章。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM