首页 > 技术文章 > Jenkins参数化构建(一)之 Maven Command Line传递TestNG构建参数

xiaochengzi 2018-01-09 12:27 原文

 1. Maven使用 -D参数名称 将参数传递至所运行项目

Maven指定TestNg.xml文件

clean test -DsuiteXmlFile=src/main/resources/testng.xml

Maven指定TestNg的groups

clean test -Dgroups=group1,group2

是否跳过测试用例

<skipTests>false</skipTests>

向代码中传递参数

systemPropertyVariables
   <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <systemPropertyVariables>
                        <environment>${env.USER}</environment>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
2. command line中设置值 mvn clean test -Denv.USER=UAT
3. 代码中获取 System.getProperty("environment”)
4. 可以直接在pom文件中设置值,command line没有设置就用默认设置值,否则用command line设置的值

 

2.pom.xml中配置testNG运行参数

  1. 指定运行的TestNg.xml文件,suitXmlFile标签中的路径依据实际路径填写
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>

2. 指定TestNg运行的groups

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
        <configuration>
          <groups>functest,perftest</groups>
        </configuration>
      </plugin>

3.传递运行参数

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20.1</version>
        <configuration>
          <systemPropertyVariables>
            <propertyName>firefox</propertyName>
          </systemPropertyVariables>
        </configuration>
      </plugin>

 4.指定testnames

官方文档:http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html 

推荐阅读