0

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?

Nexussim Lements
  • 535
  • 1
  • 15
  • 47
  • I've just taken your method and it executed all 7/7 test classes I've passed to that method. Try to leave only skipped classes in your list and retry. I think the issue is somewhere out of the code you're demonstrating.. – Alexey R. Aug 20 '21 at 12:18
  • I've cheked that if the asserts inside the tests fail, the remaining tests are not executed – Nexussim Lements Aug 20 '21 at 12:21
  • Just added explicit `Assert.fail()` to one of my tests. Still showing all tests executed but 1 failed. No skipped. – Alexey R. Aug 20 '21 at 12:23
  • @NexussimLements are you using the latest version of testng? – Gautham M Aug 21 '21 at 16:45

0 Answers0