扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
XmlTest中含有group, package, classes
创新互联专注于三亚企业网站建设,响应式网站开发,商城系统网站开发。三亚网站建设公司,为三亚等地区提供建站服务。全流程按需网站策划,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务初始化XmlClass,包含method, include, exclude
public class RunWithTestNgXml {
public static void main(String[] args) {
//Receive the arguments from command including groups, classes, package and so on
MapnodeValues = parseArgs(args);
ListxmlSuites = new ArrayList();
try {
//Could execute multiple suites
xmlSuites.add(getXmlSuite(nodeValues));
//Execute testng suites
TestNG testNG = new TestNG();
testNG.setXmlSuites(xmlSuites);
testNG.run();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//Generate XmlSuite
private static XmlSuite getXmlSuite() throws ClassNotFoundException {
XmlSuite suite = new XmlSuite();
suite.setName("Suites");
suite.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE);
//Set parallel as class
suite.setParallel(XmlSuite.ParallelMode.CLASSES);
//Set thread as 1
suite.setThreadCount(1);
//Set suite parameters
MapsuiteParams = generateSuiteMap();
suite.setParameters(suiteParams);
//Set test
ListxmlTests = getXmlTests(suite);
suite.setTests(xmlTests);
//if needed, also can write as testng.xml file
writeTestNgXml(suite);
return suite;
}
//Generate XmlTests
private static ListgetXmlTests(XmlSuite suite) {
ListxmlTestsList = new ArrayList();
XmlTest xmlTest = new XmlTest();
xmlTest.setName("Test");
xmlTest.setXmlSuite(xmlSuite);
//Set groups
Listgroups;
xmlTest.setIncludeGroups(groups);
//Set Packages
ListxmlPackages = new ArrayList();
xmlTest.setXmlPackages(xmlPackages);
//Set Classes
ListxmlClassList = new ArrayList();
xmlTest.setXmlClasses(xmlClassList);
xmlTestsList.add(xmlTest);
return xmlTestsList;
}
//Write testng.xml to disk
private static void writeTestNgXml(XmlSuite suite) {
String xmlStr = suite.toXml();
FileWriter writer = null;
try {
writer = new FileWriter( new File(C:/testng.xml"), false);
writer.write(xmlStr);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
writer.flush();
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
四、执行使用command 执行main方法
cd {workspace}/build/libs/
java -cp {project}.jar com...RunWithTestNgXml groups=smoke,P0,test classes=${CLASSES} packages=${PACKAGES}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流