测试中的 Bean shell 脚本



我想在testNG中使用bean shell脚本的方法名称选择多个方法.xml这是我当前的测试.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

在这里,我可以一次选择一种方法 time.is 可以使用 beanshell 脚本选择多个方法?或者我可以使用循环/在豆子地狱中允许循环吗?

当然,

您可以在 BeanShell 脚本中选择多个测试。基本上,TestNG为套件中的每个@Test方法调用脚本(例如在<packages>中定义),并向它传递其他变量(http://testng.org/doc/documentation-main.html#beanshell)。您可以在此处定义自己的函数等。唯一重要的条件是 - 如果您想要或不想包含"当前"方法来测试套件,则必须返回 true/false。因此,例如,如果您将脚本更改为:

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

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

最新更新