在JUnit 3中,我只是打电话给
suite.addTestSuite( MyTest.class )
但是,如果MyTest是一个不扩展TestCase的JUnit 4测试,则不起作用.我应该怎么做才能创建一套测试?
自己找到了答案:这里
像这样:
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 }
对于需要与新v4样式共存的大型3.8样式套件/测试的用户,您可以执行以下操作:
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; } }