title: Running specific tests with TestNG programmatically
body: <p>While tests are being executed, I populate a List of failedTests.
  I want to rerun these tests programmatically when the suite completes.
  Following the TestNG documentation, I implemented the following logic:</p>
  
  <pre><code>public void retrySuiteVirtXml(){
      TestListenerAdapter tla = new TestListenerAdapter();
      TestNG tng = new TestNG();
      tng.addListener(tla);
  
      XmlSuite suite = new XmlSuite();
      suite.setName("Retry Suite");
  
      for (ITestResult testResult : failedTests){
          XmlTest xmlTest = new XmlTest();
          xmlTest.setSuite(suite);
  
          String newTestName = testResult.getName();
          xmlTest.setName(newTestName);
  
          List&lt;XmlClass&gt; xmlClasses = new ArrayList&lt;&gt;();
          xmlClasses.add(new XmlClass(testResult.getTestClass().getName()));
          xmlTest.setXmlClasses(xmlClasses);
  
          xmlTest.getClasses().addAll(xmlClasses);
          suite.addTest(xmlTest);
      }
  
      List&lt;XmlSuite&gt; suites = new ArrayList&lt;&gt;();
      suites.add(suite);
      tng.setXmlSuites(suites);
      //tng.run();
      tng.runSuitesLocally();
  
  }
  </code></pre>
  
  <p>However, this block runs every test that appears in the class of a failed test.
  I cannot figure out how to make the TestNG only run the failed tests (List failedTests).</p>
  
  <p>Any help will be much appreciated. Thanks.</p>