4

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!

orbfish
  • 7,381
  • 14
  • 58
  • 75

3 Answers3

5

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

Fabian Steeg
  • 44,988
  • 7
  • 85
  • 112
1

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
  • 709
  • 4
  • 5
0

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
  • 138,234
  • 66
  • 282
  • 345
  • 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 Jul 29 '10 at 18:09
  • Maybe I misunderstood - "run as" creates source code? I'll give it a try. – orbfish Jul 31 '10 at 14:57
  • 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 Aug 01 '10 at 12:48
  • 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 Aug 03 '10 at 15:45
  • 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 Aug 03 '10 at 20:49
  • This is the most practical answer. Thanks. – Peter Ajtai Dec 04 '10 at 03:53