2012-02-08 140 views
3

我正在为maven使用Apache的Surefire JUnit插件。重复JUnit3测试

我想在JUnit 3.x中重新运行测试套件。这在JUnit 4中很容易实现,它提供了'Parameterized'注解。

你知道我如何在JUnit 3.x中做同样的事吗?

我的目标是运行整套测试两次,以便将两个不同的测试数据接种到所有测试中。

回答

3

在JUnit 3.x中,您可以定义自己的测试套件。如果您添加

public static Test suite() 

方法给yout 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; 
}