suite.setName("TmpSuite");
XmlTest test = new XmlTest(suite);
test.setName("TmpTest");
List<XmlClass> classes = new ArrayList<XmlClass>();
classes.add(new XmlClass("test.failures.Child"));
test.setXmlClasses(classes) ;
然后你可以将XmlSuite传递给TestNG:
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();
完整的API请参考javadoc。
5.14 - BeanShell and advanced group selection
如果testng.xml中的<include>和<exclude>标签还不足够满足你的需要,你可以使用BeanShell表达式来决定是否需要将一个特定的测试方法包含在测试操作中。只需要在<test>标签下指定这个表达式:
<test>
<method-selectors>
<method-selector>
<mce:script language="beanshell"><!--
groups.containsKey("test1")
--></mce:script>
</method-selector>
</method-selectors>
<!-- -->
<test>
<method-selectors>
<method-selector>
<mce:script language="beanshell"><!--
groups.containsKey("test1")
--></mce:script>
</method-selector>
</method-selectors>
<!-- -->
当发现testng.xml中有<script>标签,TestNG将忽略当前<test>标签中的以后的组和方法的<include>和<exclude>标签:BeanShell表达式将是决定一个测试方法是否包含的唯一方法。
这里有一些BeanShell脚本的额外信息:
* 必须返回boolean值。除了这个约束,任何有效的BeanShell代码都被容许.(例如,你可能想在工作日返回true而在周末返回false,这将容许你更加日期不同差异性的运行测试。
* TestNG为了便利定义了以下变量:
java.lang.reflect.Method method: 当前测试方法
org.testng.ITestNGMethod testngMethod: 当前测试方法的描述
java.util.Map<String, String> groups: 当前测试方法所属组的Map
* 你可能需要在你的表达式前后增加CDATA声明(如上面所示)以避免讨厌的xml转义字符
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-72701-19.html
有着不属于这个年龄的成熟
炒作而已
面对给中华民族带来史上最深重灾难的日本