views:

40

answers:

1
+1  Q: 

TestNG test reuse

Need some help thinking in TestNG terms. I have a large third party test suite written in TestNG and I'd like to be able to compose tests from it and run them from Intellij or Maven

Is it possible to compose tests together programmatically and still leverage the runners built into these other frameworks. In JUnit you could do this:

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class ExampleTest extends TestCase {

    public static Test suite() {
        final TestSuite suite = new TestSuite("suite");
        suite.addTestSuite(org.thirdparty.tests.FooTest.class);
        suite.addTestSuite(org.thirdparty.tests.BarTest.class);
        suite.addTestSuite(org.thirdparty.tests.BazTest.class);
        return suite;
    }
}

Can't seem to find an equivalent TestNG concept. I see there's an XmlSuite class that allows a suite to be programmatically created, but I see no way to hand this off to a test runner like Maven Surefire or Intellij.

Is it possible to do the simple and direct and create a Test which hands over the XmlSuite object or otherwise programmatically compose tests without also having to control the test runner?

+1  A: 

Hi David,

It's a bit contrived, but you could always create an XmlSuite object, save the output of toXml() to a file and use the tag of Surefire to reference that file.

Does this answer your question?

Cedric Beust
and interesting creative answer :)
Pascal Thivent
Thanks :-)If you found this one creative, you should see the couple other that crossed my mind...
Cedric Beust
Thanks, Cedric. It does answer the question in that it appears to not be possible :) I'm getting by fine without it.On a side note, it might be nice to have an @XmlSuite annotation which could either point to a testng file in the classpath (making the surefire tag irrelevant) or it could be applied to a static method that produces and returns an XmlSuite (making the xml file irrelevant).
David Blevins
David: Interesting suggestion about @XmlSuite, I'll think about it.
Cedric Beust