在 TestNG xml 文件中,如何在 beanshell 中调用另一个 java 方法?

在 TestNG xml 文件中,如何在 BeanShell 中调用另一个 java 方法?下面是我在 testNG xml 文件方法选择器标签中使用的脚本。但不知何故,它没有选择任何测试用例来运行,也没有给出任何错误。validatePredicates 是另一个 java 类 com.myProject.TestNG.TestClass.validatePredicates 中编写的静态 java 方法


            <script language="beanshell">

                <![CDATA[return com.myProject.TestNG.validatePredicates(groups,"myGroup&bug");

            ]]>

            </script>


忽然笑
浏览 78回答 2
2回答

哆啦的时光机

问题出在以下方法上:com.myProject.TestNG.validatePredicates(String[] groups, String testingExpression)。实际上,我期望组位于 String 数组中,但 testNg 将组传递到hashMap.&nbsp;所以我换成String[]Map,问题就解决了。

慕勒3428872

或者,您也可以使用<method-selectors>. 这可以放在 <test>或<suite>标签下,具体取决于您是否希望它应用于单个测试或套件中的所有测试。<method-selectors>&nbsp; &nbsp; <method-selector>&nbsp; &nbsp; &nbsp; <script language="beanshell"><![CDATA[&nbsp; &nbsp; &nbsp; &nbsp; groups.containsKey("myGroup&bug") ;&nbsp; &nbsp; &nbsp; &nbsp; ]]>&nbsp; &nbsp; &nbsp; &nbsp; </script>&nbsp; &nbsp; &nbsp;</method-selector>&nbsp; &nbsp; </method-selectors>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java