【问题标题】:comma separated parametrized maven ONLY tests one testng file逗号分隔的参数化 maven 仅测试一个 testng 文件
【发布时间】:2018-01-08 14:51:00
【问题描述】:

我遇到了一个 Maven 问题,在互联网上我找不到任何答案。如果有人可以帮助我,我将不胜感激。我的目标是测试作为参数发送到 POM 的 2 个 testng 文件:

mvn clean test -DsuiteXmlFiles=1.xml,2.xml

POM 文件是:

<plugins>
        <!-- Following plugin executes the testng tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <!-- Suite testng xml file to consider for test execution -->
                <suiteXmlFiles>
                    <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
                </suiteXmlFiles>
                <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>
        <!-- Compiler plugin configures the java version to be usedfor compiling 
            the code -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>

但是,当我运行时,它只运行 2.xml 文件并运行两次!!!

尝试了许多选项,但无论第二个 xml 文件是什么,它都会完全忽略第一个并运行第二个两次。

有人可以帮忙吗?

谢谢

【问题讨论】:

  • 您能否详细说明您尝试过的其他选项?

标签: maven testng maven-surefire-plugin


【解决方案1】:

你的万能插件应该如下所示

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.15</version>
    <configuration>
        <suiteXmlFiles>${file}</suiteXmlFiles>
        <skipTests>false</skipTests>
    </configuration>
</plugin>

密切关注&lt;suiteXmlFiles&gt;${file}&lt;/suiteXmlFiles&gt;

所以现在你可以通过

传入多个套件文件
mvn clean test -Dfile=src/test/resources/suite-one-with-execution.xml, src/test/resources/suite-two-with-execution.xml

更多详情可以参考我的博文here

【讨论】:

  • 感谢 Krishnan,我尝试了您的建议,但问题仍然存在。基本上,“,”之前的内容无关紧要,它只会在“,”之后运行testng文件并运行两次。还有其他解决方案吗?还尝试了不同版本的surefire
  • @reza - 你可以尝试使用surefire插件版本2.15看看吗?我想弄清楚这里出了什么问题,因为如果你看一下我分享的博客文章,它就是一个有效的例子。另外请确保您使用的是最新版本的 TestNG,即6.13.1(此时)
  • 刚刚又试了一次,同样的结果,太奇怪了,我以前也有这个,但不知道为什么这个项目不能我正在使用 org.testng testng6.8compile and 2.15 for surefire
【解决方案2】:

终于明白问题出在哪里了,不知为何,xml文件中的Suite名字应该不一样!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-20
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多