How to share JUnit BeforeClass logic among multiple test classes

后端 未结 3 1344
感情败类
感情败类 2021-01-31 17:13

Currently, all of my JUnit tests extend from a common base class that provides methods tagged with @BeforeClass and @AfterClass annotations - all thes

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 17:38

    You can use the @BeforeClass and @AfterClass IN THE SUITE CLASS.

    This will run the methods before any of the test classes in the suite execute and after all the test classes finish (respectively)

    This way you can run them only once.

    //..usual @RunWith etc annotations here
    public class MySuite{
    
    @BeforeClass
    public static void setup(){
    
    }
    
    @AfterClass
    public static void tearDown(){
    
    }
    
    }
    

提交回复
热议问题