我正在为 Maven 使用 Apache 的 Surefire JUnit 插件。
我想在 JUnit 3.x 中重新运行一个测试套件。这在提供“参数化”注释的 JUnit 4 中很容易实现。
你知道我如何在 JUnit 3.x 中做同样的事情吗?
我的目标是运行整个测试套件两次,以便将两个不同的测试数据植入所有测试中。
在 JUnit 3.x 中,您可以定义自己的测试套件。如果你添加
public static Test suite()
使用 JUnit 类的方法,而不是 JUnit 将运行返回变量中定义的所有方法。您可以查看JUnit 和 junit.framework.TestSuite - No runnable methods (to the question) 或http://junit.org/apidocs/junit/framework/TestSuite.html
你也可以这样做:
public static Test suite() {
TestSuite suite = new TestSuite(YouTestClass.class);
suite.addTest(new TestSuite(YouTestClass.class)); //you want to run all twice
// suite.addTest(new YouTestClass("foo", 0);
// for (int i = 0; i < TEST_SETALL.length; i++) {
// suite.addTest(new YouTestClass("setAllTest",i ));
// }
Test setup = new TestSetup(suite) {
protected void setUp() throws Exception {
// do your one time set-up here!
}
protected void tearDown() throws Exception {
// do your one time tear down here!
}
};
return setup;
}