views:

45

answers:

3

When I use Eclipse to create a JUnit test suite, it does not detect any existing tests, and warns "No test classes selected."

I started from the test class package (test/com/.../package), and the package is selected. There are several JUnit tests there, also created through the same version of Eclipse, but there is no way to select them.

I am using JUnit 4.

Thanks!

A: 

In Eclipse, you can simply right-click on the project / package you want to run tests in and select Run as > Junit Test - you can avoid needing to programmatically create a test suite class completely.

matt b
Well, if you never want to automate them, which is the whole point....
orbfish
Huh? I'm referring to creating a `TestSuite` class which programmatically lists which tests to include. Eclipse can execute all your tests in a project without one, and so can Ant/Maven etc. Can you please explain how you are trying to invoke the tests from Eclipse?
matt b
Maybe I misunderstood - "run as" creates source code? I'll give it a try.
orbfish
No, `run as` executes classes/applications/etc. My point is that in Eclipse you don't need to bother with the `TestSuite` creation - Eclipse's test runner can run a series of unit tests without one (just by being told through the GUI which to run).
matt b
The point of creating the suite is so that the tests can be automated. If you have to sit there and select "run as," then you're not a nightly/hourly batch process, you're a person.
orbfish
Right, but typically you don't automate your tests by launching them in Eclipse. You do so with Ant or Maven, both of which have features which can handle running all tests in a given folder/package/etc, negating the need to manually create a TestSuite. Eclipse has the same type of feature, which was my only point.
matt b
A: 

A Suite that works for me is :

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
...

@RunWith(Suite.class)
@SuiteClasses( { MyTest.class })
public class SeleniumSuite {

    ...

}

This helps if you want to run just a subset of tests defined in a package. What are you tests called? Try re-factoring them so they are called either Test*.java or *Test.java.

Jatin
They're the normal *Test.java that Eclipse creates.
orbfish
+1  A: 

The wizard for creating a suite currently only works with JUnit 3 tests, see corresponding bugzilla entry.

Fabian Steeg
How long has JUnit 4 been around? Well, that explains it, thanks!
orbfish