找到了我自己的问题的答案:)在发布我的问题之前,我已经尝试了一下,但是它对我没有用。但是我现在意识到这是因为我们的测试框架调用junit的方式与默认方式不同,因此它没有调用以下解决方案所需的“
suite”方法。在Eclipse中,如果我使用捆绑的junit运行器直接执行一个Test / TestCase,它运行良好。
在junit 3中每个类一次进行此设置/拆卸的方法是使用TestSuite。这是junit.org上的示例:
有没有办法让setUp()只运行一次?
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 "); } };}


