如何从 Maven 命令行运行 testng.xml

新手上路,请多包涵

我的 pom.xml 中有以下条目,其中包含配置中定义的套件文件。

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</plugin>

使用 Maven 在 cmd 中运行它的正确方法是什么?我可以使用下面的命令运行测试,但是当它已经在 pom 中定义时,在命令中再次指示 testng.xml 是没有意义的。

  mvn clean test -DsuiteXmlFile=testng.xml

原文由 jeffsia 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 897
1 个回答

最简单的解决方案是,在 surefire 插件中添加以下行。

 <suiteXmlFiles>
    <!-- pass testng.xml files as argument from command line -->
    <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>

并按如下方式运行您的 xml 文件,

 mvn clean test -Dsurefire.suiteXmlFiles=/path/to/testng.xml

原文由 Prakash Palnati 发布,翻译遵循 CC BY-SA 3.0 许可协议

推荐问题