我正在测试一个API,我有一些参数化的Jenkins构建。
对于某些测试,(我将调用测试一)我希望选择环境和端口号
对于其他人,(我将称之为测试二)我想选择环境,端口号和一些搜索字符串参数(对于上下文,假日的星级评定)。
我正在使用TestNG运行。我简化了问题来解释:
测试一个TestNG Suite.XML:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1">
<parameter name="testName" value="Test 1"/>
<parameter name="description" value="some stuff"/>
<test name="test1">
<!--SERVER AND TARGET PARAMS-->
<parameter name="environment" value="${environment}"/>
<parameter name="port" value="${port}"/>
<parameter name="currency" value="GBP"/>
<!--tests to run-->
<classes>
<class name="com.mycompany.abc.api.TestOne"/>
</classes>
</test>
测试两个TestNG套件xml:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1">
<parameter name="testName" value="Test 2"/>
<parameter name="description" value="some stuff"/>
<test name="test2">
<!--SERVER AND TARGET PARAMS-->
<parameter name="environment" value="${environment}"/>
<parameter name="port" value="${port}"/>
<!--Searching Parameters-->
<parameter name="starRatingOne" value="${starRatingOne}"/>
<parameter name="starRatingTwo" value="${starRatingTwo}"/>
<parameter name="currency" value="GBP"/>
<!--tests to run-->
<classes>
<class name="com.mycompany.abc.api.TestTwo"/>
</classes>
</test>
我的POM文件摘要:
<groupId>co.uk.mycompanytest.project</groupId>
<artifactId>super-api-automation</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<sl4j.version>1.7.7</sl4j.version>
<suiteFile>${suiteFile}</suiteFile>
<environment>${environment}</environment>
<port>${port}</port>
<starRatingOne>${starRatingOne}</starRatingOne>
<starRatingTwo>${starRatingTwo}</starRatingTwo>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<systemProperties>
<property>
<name>javax.xml.parsers.SAXParserFactory</name>
<value>org.apache.xerces.jaxp.SAXParserFactoryImpl</value>
</property>
<property>
<name>user.language</name>
<value>en</value>
</property>
</systemProperties>
<!--<testFailureIgnore>true</testFailureIgnore>-->
<suiteXmlFiles>
<suiteXmlFile>${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<environment>${environment}</environment>
<environment>${port}</environment>
<starRatingOne>${starRatingOne}</starRatingOne>
<starRatingTwo>${starRatingTwo}</starRatingTwo>
</systemPropertyVariables>
<properties>
<property>
<name>parallel</name>
<value>methods</value>
</property>
<property>
<name>threadCount</name>
<value>1</value>
</property>
<property>
<name>dataproviderthreadcount</name>
<value>1</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
My Two Jenkins Jobs是参数化版本,因此测试人员可以随意传递参数: -
测试一:
测试二:
TestOne的Jenkins工作中的Maven目标是:
clean test -DsuiteFile="src/test/resources/suites/testng_testOne.xml" -Denvironment=$environment -Dport=$port -DstarRatingOne=$starRatingOne -DstarRatingTwo=$starRatingTwo
测试二:
clean test -DsuiteFile="src/test/resources/suites/testng_testOne.xml" -Denvironment=$environment -Dport=$port
我收到的第二项工作的错误当然是: -
Parsing POMs
ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[ERROR] Resolving expression: '${starRatingOne}': Detected the following recursive expression cycle in 'starRatingOne': [starRatingOne] @
[ERROR] Resolving expression: '${starRatingTwo}': Detected the following recursive expression cycle in 'starRatingTwo': [starRatingTwo] @
基本上我需要知道的是:我如何才能拥有需要不同数量的params但只有一个POM文件的单独的Jenkins作业?我想我需要在maven目标中传递匹配参数的作业被忽略或具有默认值。因此,如果没有找到starRatingOne param,那么请不要尝试使用它(也许该工作的API请求不会被要求获得星级评分)。
任何帮助表示赞赏