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

查看:1151
本文介绍了如何从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时,在命令中再次指示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天全站免登陆