如何从maven命令向testng.xml文件传递特定的测试方法名称
我希望通过使用maven命令将特定的测试方法传递到testng.xml文件,以及如何在testng.xml中读取该参数如何从maven命令向testng.xml文件传递特定的测试方法名称,maven,testng,maven-surefire-plugin,Maven,Testng,Maven Surefire Plugin,我希望通过使用maven命令将特定的测试方法传递到testng.xml文件,以及如何在testng.xml中读取该参数 <test name="Automation Test Results" > <method-selectors> <method-selector><script language="beanshell"><![CDATA[ testngMethod.getMethodName().c
<test name="Automation Test Results" >
<method-selectors>
<method-selector><script language="beanshell"><![CDATA[
testngMethod.getMethodName().contains(System.getProperty("testToRun"))
]]></script></method-selector>
</method-selectors>
<packages>
<package name="com.mycompany.*"></package>
</packages>
</test>
pom.xml中使用的maven surefire插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
org.apache.maven.plugins
maven surefire插件
2.17
testng.xml
下面是我的testng.xml文件
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1" >
<test name="Nopackage" >
<classes>
<class name="com.ariveguru.tests.EServeSanityTest" />
</classes>
</test>
</suite>
您想如何处理测试方法的名称
如果要包括/排除某些测试,Surefire插件允许,但不允许单独的方法。要实现这一点,如果可行,您可以将有问题的方法移动到它们自己的测试类中。您可以将其作为jenkins的参数传递,并在testng.xml中更新以下内容
<test name="Automation Test Results" >
<method-selectors>
<method-selector><script language="beanshell"><![CDATA[
testngMethod.getMethodName().contains(System.getProperty("testToRun"))
]]></script></method-selector>
</method-selectors>
<packages>
<package name="com.mycompany.*"></package>
</packages>
</test>
从jenkins中再添加一个参数-dtestorun=testToTest如果是通过mvn,我可以使用“mvn-Dtest=Sanitytest#case creation clean test”,但在jenkins中,上面的命令无效,因此我添加了testng.xml以不同的方式进行尝试。很抱歉,您在问题中没有提到jenkins,而且它也没有相应的标记。您在哪里添加了
testng.xml
?Jenkins工作的基本配置是什么?再次抱歉,如果实际信息只是逐渐减少,则很难给出适当的答案。另外,不要忘记添加maven存储库: