如何从 Maven 命令行运行 testng.xml [英] How to run testng.xml from Maven command line

查看:69
本文介绍了如何从 Maven 命令行运行 testng.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following entry in my pom.xml with the suite file defined in the configuration.

<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 是没有意义的.

What is a the correct way to run this in cmd using maven? I am able to run the test with the command below but it doesn't make sense to indicate the testng.xml again in the command when it's already defined in the pom.

 mvn clean test -DsuiteXmlFile=testng.xml

推荐答案

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

Easiest solution would be, add the below lines in surefire plugin.

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

然后运行您的 xml 文件,如下所示,

And run your xml file as below,

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

这篇关于如何从 Maven 命令行运行 testng.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆