tags:

views:

1676

answers:

2

In JUnit 3 I simply called

suite.addTestSuite( MyTest.class )

However if MyTest is a JUnit 4 test which does not extend TestCase this doesn't work. What should I do instead to create a suite of tests?

+3  A: 

Found the answer myself: here

Like so:

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

@RunWith(Suite.class)
@Suite.SuiteClasses({
  TestCalculatorAddition.class,
  TestCalculatorSubtraction.class,
  TestCalculatorMultiplication.class,
  TestCalculatorDivision.class
})
public class CalculatorSuite {
    // the class remains completely empty, 
    // being used only as a holder for the above annotations
}
Epaga
+3  A: 

For those with a large set of 3.8 style suites/tests that need to coexist with the new v4 style you can do the following:

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

@RunWith(Suite.class)
@Suite.SuiteClasses({
  // Add a JUnit 3 suite
  CalculatorSuite.class,
  // JUnit 4 style tests
  TestCalculatorAddition.class,
  TestCalculatorDivision.class
})
public class CalculatorSuite {
    // A traditional JUnit 3 suite
    public static Test suite() {
        TestSuite suite = new TestSuite();
        suite.addTestSuite(TestCalculatorSubtraction.class);
        return suite;
}
Josh