试图用Jenkins参数值覆盖testNG. xml套件参数。但是值没有被替换。想要用Jenkin参数替换testNG参数。有人可以指导吗。版本使用TestNG'7.5'和OpenJDK'15'
Maven目标:干净的编译测试-DtestNGXml=${testNGXml}-D有环境名称=${有环境名称}-D有环境客户ID=${有环境客户ID}
测试NG. xml
<suite name="HealthCheck_Suite" parallel="classes" thread-count=“1”>
<parameter name="environmentName" value="DEV" />
<parameter name="environmentClientID" value="BE11TEST" />
<test name="iOS_HealthCheck">
<classes>
<class name="MobileLoginTest">
<methods>
<include name="loginHealthCheckScript" />
</methods>
</class>
</classes>
</test>
</suite>
Pom Xml surefire插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine>
<suiteXmlFiles>
<suiteXmlFile>${testNGXml}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>```
这里有一个简化的设置,应该适合你。
让我们假设您的测试如下所示:
package com.rationaleemotions;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class AppTest {
@Test
@Parameters({"environmentName", "environmentClientID"})
public void testMethod(String environmentName, String environmentClientID) {
System.err.println("EnvironmentName: " +
environmentName + ", environmentClientID: " + environmentClientID);
}
}
套件xml如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="jenkins_Suite" parallel="classes" thread-count="1">
<parameter name="environmentName" value="DEV"/>
<parameter name="environmentClientID" value="BE11TEST"/>
<test name="jenkins_test">
<classes>
<class name="com.rationaleemotions.AppTest"/>
</classes>
</test>
</suite>
我有一个7.6.1
的TestNG依赖项,我的surefire插件配置如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
我现在创建一个参数化作业,它基本上有2个字符串参数:
env
-这代表环境clientId
-这代表客户端IDmaven的目标如下所示
clean test -DenvironmentName="${env}" -DenvironmentClientID="${clientId}"
这应该允许您通过JVM参数覆盖套件xml文件中定义的参数值。
这是可能的,因为TestNG已经允许您覆盖中的值
所以: