public static TestNG getTestRunner(String clazz, String method, boolean isThrowException) {
TestNG tng = new TestNG();
XmlSuite suite = new XmlSuite();
XmlTest test = new XmlTest(suite);
test.setName("run testng");
XmlClass xmlClazz = new XmlClass(clazz);
try {
/**
* 为了兼容testng 5.11(以下版)和5.12(以上版),采用了try catch
*/
List includes = xmlClazz.getIncludedMethods();
try {
// 下列代码其实就是includes.add(new XmlInclude(method)); <br>
// 采用反射构造是为了在testNg5.11下也可以编译通过
Class xmlInclude = Class.forName("org.testng.xml.XmlInclude");
Constructor constructor = xmlInclude.getConstructor(String.class);
includes.add(constructor.newInstance(method));
} catch (Throwable e) {
includes.add(method);
}
xmlClazz.getExcludedMethods().add(method + ".+");
} catch (Throwable e) {
}
test.getXmlClasses().add(xmlClazz);