Run TestNG test from another class
<p>Is there any way to run TestNG test from another java class.</p>

<pre><code>@Test
public void f(Integer n, String s) {
}
</code></pre>

<p>I need to run the same method in a single suite with different arguments.(Inside for loop)</p>

<p>Is it possible?</p>

<p>Also, I see that dataprovider method should return <code>Object[][]</code>. This works fine for methods with two arguments. Can we send more than two arguments??</p>

<pre><code>@DataProvider
public Object[][] dp() {
    return new Object[][] { new Object[] { 1, "a" }, new Object[] { 2, "b" }, };
}

@Test(dataProvider = "dp")
public void f(Integer n, String s, char c, double d, String s2) {
}
</code></pre>

<p>I am trying to do it by using some TestNG classes</p>

<pre><code>public static void main(String[] args) {

    List&lt;XmlClass&gt; classes = new ArrayList&lt;&gt;();
    classes.add(new XmlClass("com.test.PortalTest"));

    XmlSuite suite = new XmlSuite();
    suite.setName("Portal Test Suite");

    XmlTest test = null;
    for (int index = 0; index &lt; 7; index++) {
        test = new XmlTest();
        test.setName("Portal Test - " + index);
        test.setXmlClasses(classes);
        test.addParameter("downloadFileIndex", String.valueOf(index));
        suite.addTest(test);
    }

    List&lt;XmlSuite&gt; suites = new ArrayList&lt;XmlSuite&gt;();
    suites.add(suite);

    TestListenerAdapter testListenerAdapter = new TestListenerAdapter();

    TestNG testNG = new TestNG();
    Class[] classesClasses = {PortalTest.class};
    testNG.setTestClasses(classesClasses);
    testNG.setXmlSuites(suites);
    testNG.addListener(testListenerAdapter);
    testNG.run();

    System.out.println("Passed : " + testListenerAdapter.getPassedTests());
    System.out.println("Failed : " + testListenerAdapter.getFailedTests());
    System.out.println("Skipped : " + testListenerAdapter.getSkippedTests());

}
</code></pre>

<p>I use below code to run method having <code>@Test</code> for one time. How can i run the <code>@Test</code> method multiple times in a same test.</p>

<pre><code>TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { PortalTest.class });
testng.addListener(tla);
testng.run();
</code></pre>