Junit 4全球设置和拆解

时间:2017-04-27 13:34:57

标签: java testing junit

我希望在我的整个测试中使用setupteardown的单独课程。 我设法创造了一个这样做的课程(它有点棘手,希望有更好的方法......)。

但是当从intellij运行特定测试时(右键单击该文件),不会调用安装程序类。

这是我的设置类

public class BaseTest extends TestCase {

    private final static Logger logger = Logger.getLogger(BaseTest.class);

   @Override
   protected void setUp() throws Exception {
       ///Some setup code ...

   }

    @Override
    protected void tearDown() throws Exception {
        //Put teardown code here 
    }

    @Test
    public void testMethodA() {} // For some reason i must add this method, for my code to run

}

1 个答案:

答案 0 :(得分:3)

public class BaseTest extends TestCase {

    private final static Logger logger = Logger.getLogger(BaseTest.class);

    @Before
       protected void setUp() throws Exception {
           ///Some setup code ...

       }

    @After
    protected void tearDown() throws Exception {
        //Put teardown code here 
    }

    @Test
    public void testMethodA() {} // For some reason i must add this method, for my code to run

}