How can I run JUnit test suites in TestNG?

10 views
Skip to first unread message

larba

unread,
Nov 30, 2005, 7:27:00 AM11/30/05
to testng-users
Hi!

I have an existing JUnit test suite that looks something like this:

public static Test suite() {
TestSuite suite = new TestSuite("MyTestSuite");

suite.addTest(mypackage.PackageSuite.suite());
suite.addTest(mypackage2.Package2Suite.suite());
(...)

return suite;
}

Each PackagexSuite.suite() does this:

public static Test suite() {
TestSuite suite = new TestSuite("TestASuite");
suite.addTestSuite(TestAa.class);
suite.addTestSuite(TestAb.class);
(...)
return suite;
}

I.e., I have one suite that uses TestCases in other "sub suites".
I know I can run each sub suite by itself (using junit=true), but is
there a way to
run the first suite directly (and thus not having to specify each sub
suite)?

Kind regards,

Lasse

larba

unread,
Nov 30, 2005, 7:36:09 AM11/30/05
to testng-users

larba wrote:

I forgot to mention that when I run the suite above, I get the
following error message:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
>= 1
at java.util.Vector.elementAt(Vector.java:432)
at junit.framework.TestSuite.testAt(TestSuite.java:215)
at org.testng.junit.JUnitClassFinder.<init>(JUnitClassFinder.java:68)
at org.testng.TestRunner.initMethods(TestRunner.java:247)
at org.testng.TestRunner.init(TestRunner.java:192)
at org.testng.TestRunner.init(TestRunner.java:164)
at org.testng.TestRunner.<init>(TestRunner.java:120)
at
org.testng.remote.RemoteTestNG$2.newTestRunner(RemoteTestNG.java:81)
at
org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:356)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:160)
at org.testng.SuiteRunner.run(SuiteRunner.java:126)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:99)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)

Cédric Beust ♔

unread,
Nov 30, 2005, 9:30:18 AM11/30/05
to testng...@googlegroups.com
Lasse,

It looks like a bug, I should be able to reproduce it easily with your code.  Stay tuned!

--
Cedric


On 11/30/05, larba < lasse....@gmail.com> wrote:


larba wrote:

> Hi!
>
> I have an existing JUnit test suite that looks something like this:
>
>   public static Test suite() {
>     TestSuite suite = new TestSuite("MyTestSuite");
>
>     suite.addTest(mypackage.PackageSuite.suite());
>     suite.addTest(mypackage2.Package2Suite.suite());
>    (...)
>
>     return suite;
>   }
>
> Each PackagexSuite.suite () does this:

>
> public static Test suite() {
>     TestSuite suite = new TestSuite("TestASuite");
>     suite.addTestSuite(TestAa.class);
>     suite.addTestSuite(TestAb.class);
>     (...)
>     return suite;
>   }
>
> I.e., I have one suite that uses TestCases in other "sub suites".
> I know I can run each sub suite by itself (using junit=true), but is
> there a way to
> run the first suite directly (and thus not having to specify each sub
> suite)?
>
> Kind regards,
>
> Lasse

I forgot to mention that when I run the suite above, I get the
following error message:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
>= 1
        at java.util.Vector.elementAt(Vector.java:432)
        at junit.framework.TestSuite.testAt (TestSuite.java:215)

        at org.testng.junit.JUnitClassFinder.<init>(JUnitClassFinder.java:68)
        at org.testng.TestRunner.initMethods(TestRunner.java:247)
        at org.testng.TestRunner.init(TestRunner.java :192)
        at org.testng.TestRunner.init(TestRunner.java:164)
        at org.testng.TestRunner.<init>(TestRunner.java:120)
        at
org.testng.remote.RemoteTestNG$2.newTestRunner(RemoteTestNG.java:81)
        at
org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:356)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:160)
        at org.testng.SuiteRunner.run(SuiteRunner.java :126)
        at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:99)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:138)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke (Method.java:585)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)




--
Cédric

Cédric Beust ♔

unread,
Nov 30, 2005, 1:50:39 PM11/30/05
to testng...@googlegroups.com
Lasse,

I have a fix for this bug, I'll email you the jar privately.

--
Cedric


On 11/30/05, larba < lasse....@gmail.com> wrote:



--
Cédric

Cédric Beust ♔

unread,
Nov 30, 2005, 1:51:57 PM11/30/05
to testng...@googlegroups.com
On 11/30/05, larba <lasse....@gmail.com> wrote:

Yes, you can just point TestNG to your "top" suite and it will find all the other suites automatically.  Let's take this off-line and I'll show you how if you can't figure it out.

--
Cédric

Alexandru Popescu

unread,
Nov 30, 2005, 5:31:29 PM11/30/05
to testng...@googlegroups.com
#: Cédric Beust ♔ changed the world a bit at a time by saying on 11/30/2005 8:51 PM :#
Hi Cedric! Can you post the tips and tricks on the mailing list, so that other users can read those?

many thanks,

./alex
--
.w( the_mindstorm )p.


Reply all
Reply to author
Forward
0 new messages