我正在动态创建我的testNG xml,现在我们已经为我们的测试用例引入了分组的概念。我尝试将组添加到我的testNG但不知何故它不起作用。在套件级别和测试级别尝试过,但仍然无法找出确切的问题。以下是测试级别分组的示例
以下是我的代码:
TestNG testNG = new TestNG();
List<XmlSuite> suites = new ArrayList<XmlSuite>();
for (BrowserEnvironment environment : browserEnvironments)
{
XmlSuite suite = new XmlSuite();
suite.setName(environment.getBrowser() + "-" + environment.getVersion() + "-" + suiteName);
suite.setParallel(XmlSuite.PARALLEL_METHODS);
suite.setThreadCount(threadCount);
for (String className : includeMethodsMap.keySet())
{
XmlTest test = new XmlTest(suite);
List<XmlClass> xmlClasses = new ArrayList<XmlClass>();
List<XmlInclude> methodNames = includeMethodsMap.get(className);
XmlClass xmlClass = new XmlClass(Class.forName(className));
xmlClass.setIncludedMethods(methodNames);
xmlClasses.add(xmlClass);
test.setName(xmlClass.getName().substring(1 + xmlClass.getName().lastIndexOf(".")));
test.setXmlClasses(xmlClasses);
test.addIncludedGroup(SettingMapConstants.DefaultSet);
}
suites.add(suite);
}
testNG.setXmlSuites(suites);
生成的TestNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="10" name="Firefox-43.0-_TestSuite" parallel="methods">
<test name="ExecutionSettings">
<groups>
<run>
<include name="DefaultSet"/>
</run>
</groups>
<classes>
<class name="com.zycus.automation.eproc.testcase.settingMap.ExecutionSettings">
<methods>
<include name="sudoDefaultSet"/>
</methods>
</class>
</classes>
</test>
</suite>