【问题标题】:Unable to run multiple testng xml files using maven无法使用 maven 运行多个 testng xml 文件
【发布时间】:2018-11-06 00:45:03
【问题描述】:

我的项目有两个 testNG xml 文件,TestNG.xml 和 TestNG2.xml,它们都在根文件夹中。我已经进行了如下的maven pom配置,但是当我运行时,文件“TestNG.xml”运行了两次并且TestNG2.xml保持不变。

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <suiteXmlFiles>
                    <file>TestNG2.xml</file>
                    <file>TestNG.xml</file>
                </suiteXmlFiles>
                <properties>
                    <property>
                        <name>suitethreadpoolsize</name>
                        <value>2</value>
                    </property>
                </properties>
            </configuration>
        </plugin>

我也尝试过从 cmd 运行,但同样只有 TestNG.xml 运行了两次。

mvn clean test -Dsurefire.suiteXmlFiles=TestNG2.xml,TestNG.xml

如何同时运行这两个文件?

【问题讨论】:

    标签: maven testng pom.xml


    【解决方案1】:

    您没有使用正确的标签。您必须在 suiteXmlFiles 块内重构标记名。 pom 文件应如下所示:-

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.21.0</version>
        <configuration>
            <suiteXmlFiles>
                <suiteXmlFile>TestNG2.xml</suiteXmlFile>
                <suiteXmlFile>TestNG.xml</suiteXmlFile>
            </suiteXmlFiles>
            <properties>
                <property>
                    <name>suitethreadpoolsize</name>
                    <value>2</value>
                </property>
            </properties>
        </configuration>
    </plugin>
    

    为了以防万一,如果您想从命令提示符动态运行不同的 testNG.xml,那么只需添加一个 占位符变量 pom 文件。使用 -D 开关在命令提示符中传递此占位符的值。在这种情况下,pom 文件应如下所示:-

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>${testSuite}.xml</suiteXmlFile>
    
                </suiteXmlFiles>
                <properties>
                    <property>
                        <name>suitethreadpoolsize</name>
                        <value>2</value>
                    </property>
                </properties>
            </configuration>
        </plugin>
    

    通过测试套件的命令应该是:

     mvn clean integration-test -DtestSuite=testNG
    

    【讨论】:

    • 如何从命令提示符传递多个 testNG.xml 文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    相关资源
    最近更新 更多