Maven动态执行xml文件

一、pom文件配置

            <!-- 测试代码打包 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <!-- 执行指定xml文件 -->
<!--                    <suiteXmlFiles>-->
<!--                        ./src/main/resources/testng.xml-->
<!--                    </suiteXmlFiles>-->
                    <!--动态执行xml文件。${project.basedir}项目目录,${xmlFileName}maven文件-->
                    <suiteXmlFiles>
                        <suiteXmlFile>${project.basedir}/target/classes/${xmlFileName}</suiteXmlFile>
                    </suiteXmlFiles>
                    <forkMode>once</forkMode>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                    <encoding>UTF-8</encoding>
                    <systemProperties>
                        <property>
                            <name>net.sourceforge.cobertura.datafile</name>
                            <value>target/cobertura/cobertura.ser</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>
            
    <!--为了maven打包编译时后台一直输出警告信息。导致构建失败-->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <xmlFileName></xmlFileName>
    </properties>

二、jenkins构建maven配置
命令解释:
maven参数化替换使用的占位符是 %xxx%
-DxmlFileName=%xmlFileName% 指定maven test 运行的测试集合对象。用于参数化构建传参使用,后面介绍。

在Jenkins使用Maven构建项目自动化测试前,先通过本地使用maven测试是否通过。
这里本来要将参数化构建,但参数化构建前先说明下是如何利用maven构建测试的。
1.先在IDEA上验证maven test是否生效
在${project.basedir}/target/classes/testNg/api/testng.xml 开启后,使用mvn clean test -DxmlFileName=testng.xml验证是否成功。如下图:
在这里插入图片描述
2.在jenkins上构建maven配置
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值