Why isn't my @BeforeClass method running?

后端 未结 5 1153
天涯浪人
天涯浪人 2020-12-05 13:00

I have the following code:

    @BeforeClass
    public static void setUpOnce() throws InterruptedException {
        fail(\"LOL\");
    }

A

5条回答
  •  不知归路
    2020-12-05 13:27

    the method must be static and not directly call fail (otherwise the other methods won't be executed).

    The following class shows all the standard JUnit 4 method types:

    public class Sample {
    
        @BeforeClass
        public static void beforeClass() {
            System.out.println("@BeforeClass");
        }
    
        @Before
        public void before() {
            System.out.println("@Before");
        }
    
        @Test
        public void test() {
            System.out.println("@Test");
        }
    
        @After
        public void after() {
            System.out.println("@After");
        }
    
        @AfterClass
        public static void afterClass() {
            System.out.println("@AfterClass");
        }
    
    }
    

    and the ouput is (not surprisingly):

    @BeforeClass
    @Before
    @Test
    @After
    @AfterClass
    

提交回复
热议问题