Community
Participate
Working Groups
The suite() method is not picked up by projects using junit 4.0 Steps to reproduce: 1. Create a Java Project and add Libraries->Add Library->Junit 4 2. Add the following 2 classes --RunMe.java import junit.framework.Test; import junit.framework.TestSuite; public class RunMe { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(MyTest.class); return suite; } } --MyTest import junit.framework.TestCase; public class MyTest extends TestCase { public void testFoo() { System.out.println("foo"); } } 3. Try and run test RunMe, fails with following exception java.lang.Exception: No runnable methods at org.junit.internal.runners.TestClassMethodsRunner.testAborted(TestClassMethodsRunner.java:42) at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:33) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) This works fine, if junit 3.8.1 is selected instead of junit 4.0. Furthermore, even if I start out by choosing 4.0 and then try to switch to 3.8.1 in project properties I get this error when trying to run RunMe Cannot find 'org.junit.Test' on project build path. JUnit 4 tests can only be run if JUnit 4 is on the build path
Moving to JDT/UI
JUnit 4 eliminated 'suite': It is not supported anymore. Have a look at JUnit 4 documentation on the net how multiple tests are executed now.
That's not correct. JUnit 4 didn't eliminate suite() it just provided a new alternative the Suite annotation. JUnit 4 is fully backwards compatible with JUnit 3.8.x.
So how exactly do you use JUnit 4 so that you can run 'RunMe' as listed in comment 0? AFAIK, you can still have a static method suite, but you will have to annotate your type with @RunWith(AllTests.class) Unfortunatly that doesn't work at the moment due to a bug in JUnit (NPE in Descriptor.hashCode). So you have to name your test suite @RunWith(AllTests.class) public class RunMe { public static Test suite() { TestSuite suite = new TestSuite(); suite.setName("MySuite"); suite.addTestSuite(MyTest.class); return suite; } }
(In reply to comment #4) > So how exactly do you use JUnit 4 so that you can run 'RunMe' as listed in > comment 0? How I use JUnit 4? You mean like Run->Run As->JUnit Test ? The option to run them as JUnit Test is still shown for JUnit 4 projects if a static suite() method is available.
As far I know and just verified, JUnit 4 can not run the class as specified in comment 4. For example JUnitCore.main("pack.RunMe") does not find any tests. I was wondering if you know more about the JUnit4 framework and I missed a way to do it. Yes, I also heard that Junit 4 is 'backward compatible' but it doesn't seem to be in that aspect. David, is that a JUnit bug?
So I assume this is a JUnit 4 shortcoming. Setting to remind unless I hear something else.
Martin, I've been unable to do much with JUnit over the summer, so I haven't had a lot of time to think about this until now. It appears that Eclipse 3.2 M2 does correctly run the code indicated in comment 4. Is this new behavior? Thank you for noting the NPE bug--we'll fix that in the next release of JUnit.
The code from comment 4 always workes in Eclipse, but it does'n run when you leave the line 'suite.setName("MySuite")' away: Then you get the NPE. With 'shortcoming' I meant the fact that '@RunWith(AllTests.class)' is required here. You can't just run your old class with suite anymore. So JUnit 4 isn't exactly backwards compatible. So I'm not sure if this is a JUnit 4 oversight or by design.
As of now 'LATER' and 'REMIND' resolutions are no longer supported. Please reopen this bug if it is still valid for you.