testng 中的 Bean shell 脚本

Bean shell script in testng

我想 select 多个方法基于使用 bean shell 脚本中的方法的名称 testNG.xml.This 是我当前的 testng.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="methodsuite">
<test name="test1" >
   <method-selectors>
       <method-selector>
            <script language="beanshell">
            <![CDATA[
            String str=System.getProperty("testToRun");
             testngMethod.getMethodName().contains(str);
            ]]>
            </script>
       </method-selector>
         </method-selectors>

  <packages>
       <package name=".*"></package>
   </packages> 
 </test>
 </suite

在这里我可以 select 一个方法 time.is 可以 select 使用 beanshell 脚本的多个方法?或者我可以使用 looping/is bean 中允许循环shell?

当然你可以在 BeanShell 脚本中 select 多次测试。基本上,TestNG 会为套件中找到的每个 @Test 方法调用您的脚本(例如,在 <packages> 中定义)并将附加变量 (http://testng.org/doc/documentation-main.html#beanshell) 传递给它。你可以在这里定义自己的函数等。唯一重要的条件是 - 如果你想或不包含 'current' 方法来测试套件,你必须 return true/false。因此,例如,如果您将脚本更改为:

<script language="beanshell">
    <![CDATA[
        String str = System.getProperty("testPerformance");
        testngMethod.getMethodName().startsWith(str);
    ]]>
</script>

名称以 testPerformance 开头的所有测试都将包含在测试套件中。