java JUnit 3 是否有类似于@BeforeClass 的东西?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3023091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 23:59:57  来源:igfitidea点击:

Does JUnit 3 have something analogous to @BeforeClass?

javajunit

提问by Eric Wilson

I'm forced to use JUnit 3 for a particular test suite. I understand setUp()and tearDown()serve the function of @Beforeand @After, but is there an analogue of @BeforeClassand @AfterClassfor things that should happen once before the tests start, and once after all tests are run?

我被迫将 JUnit 3 用于特定的测试套件。我的理解setUp()tearDown()服务的功能@Before@After,但有一个模拟@BeforeClass@AfterClass对事情应该发生一次测试开始之前,一旦所有的测试运行后?

采纳答案by Eric Wilson

OK, I should have searched SO better.

好的,我应该更好地搜索。

Class teardown in junit 3?

junit 3 中的类拆解?

public static Test suite() {
  return new TestSetup(new TestSuite(YourTestClass.class)) {

    protected void setUp() throws Exception {
        System.out.println(" Global setUp ");
    }
    protected void tearDown() throws Exception {
        System.out.println(" Global tearDown ");
    }
  };
}

回答by Daniel Engmann

No, this is a new feature in JUnit4.

不,这是 JUnit4 中的一个新特性。