I have created the following method to execute the methods given a list of .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);
}
}
From main method I pass them some tests:
executeTestNew("Test", Arrays.asList(
Test1.class,
Test2.class,
Test3.class,
Test4.class,
Test5.class,
Test6.class,
Test7.class,
Test8.class,
Test9.class));
The problem is that only 5 tests are executed at once, if you try to execute more than 5 in one session, they will be skipped.
EDIT:
I've checked that if the Asserts (Test NG asserts) fails in any of the tests, the remaining tests are not executed.
How can I fix this?