简体   繁体   English

如何从Maven命令将特定的测试方法名称传递到testng.xml文件

[英]How to pass particular test method name to testng.xml file from maven command

I want pass particular test method to pass to testng.xml file using maven command and how to read that parameter in testng.xml 我想通过特定的测试方法使用maven命令传递给testng.xml文件,以及如何在testng.xml中读取该参数

maven-surefire-plugin used in pom.xml pom.xml中使用的maven-surefire-plugin

<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>

Below is my testng.xml file 下面是我的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>

What would you like to do with the test method's name? 您想使用测试方法的名称做什么?

If it is to include/exclude certain tests, the Surefire Plugin allows for Inclusions and Exclusions of Tests , but not for individual methods. 如果要包含/排除某些测试,则Surefire插件允许包含和排除测试 ,但不允许单个方法。 To achieve this you could move the methods in question into their own test class, if this is feasible. 为此,如果可行,可以将相关方法移入自己的测试类。

You can pass it as an argument from jenkins and update the following in the testng.xml 您可以将其作为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>

From jenkins add one more argument -DtestToRun=testToTest 从詹金斯那里再添加一个参数-DtestToRun = testToTest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM