我创建了以下方法来执行给定 .class 列表的方法:
public static <T> void executeTestNew(String testName, List<Class<?>> test) {
try {
List<XmlClass> parsedTests = test.stream().map(XmlClass::new).collect(Collectors.toList());
TestNG testng = new TestNG();
XmlSuite xmlSuite = new XmlSuite();
xmlSuite.setGroupByInstances(true);
xmlSuite.setName(testName);
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName(testName);
xmlTest.setClasses(parsedTests);
testng.setXmlSuites(Collections.singletonList(xmlSuite));
testng.setVerbose(2);
testng.run();
} catch (Exception ex) {
System.out.printf("There was a problem executing %s \n", testName);
ex.printStackTrace();
} finally {
System.out.printf("%s finished \n", testName);
}
}
从主要方法我通过了一些测试:
executeTestNew("Test", Arrays.asList(
Test1.class,
Test2.class,
Test3.class,
Test4.class,
Test5.class,
Test6.class,
Test7.class,
Test8.class,
Test9.class));
问题是一次只执行 5 个测试,如果您尝试在一个会话中执行超过 5 个,它们将被跳过。
编辑:
我已经检查过,如果断言(Test NG 断言)在任何测试中失败,则不会执行剩余的测试。
我怎样才能解决这个问题?