2012-02-08 58 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; 
}