【发布时间】:2012-02-29 11:54:56
【问题描述】:
我正在使用 Apache 的 Surefire JUnit 插件 for maven。
我想在 JUnit 3.x 中重新运行一个测试套件。这在提供“参数化”注释的 JUnit 4 中很容易实现。
你知道我如何在 JUnit 3.x 中做同样的事情吗?
我的目标是运行整个测试套件两次,以便将两个不同的测试数据植入所有测试中。
【问题讨论】:
我正在使用 Apache 的 Surefire JUnit 插件 for maven。
我想在 JUnit 3.x 中重新运行一个测试套件。这在提供“参数化”注释的 JUnit 4 中很容易实现。
你知道我如何在 JUnit 3.x 中做同样的事情吗?
我的目标是运行整个测试套件两次,以便将两个不同的测试数据植入所有测试中。
【问题讨论】:
在 JUnit 3.x 中,您可以定义自己的测试套件。如果你添加
public static Test suite()
JUnit 类的方法比 JUnit 将运行返回变量中定义的所有方法。您可以查看JUnit and junit.framework.TestSuite - No runnable methods(问题)或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;
}
【讨论】: