How to run test methods in specific order in JUnit4?

后端 未结 18 2167
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 04:35

I want to execute test methods which are annotated by @Test in specific order.

For example:

public class MyTest {
    @Test public void          


        
18条回答
  •  爱一瞬间的悲伤
    2020-11-22 04:59

    If you get rid of your existing instance of Junit, and download JUnit 4.11 or greater in the build path, the following code will execute the test methods in the order of their names, sorted in ascending order:

    @FixMethodOrder(MethodSorters.NAME_ASCENDING)
    public class SampleTest {
    
        @Test
        public void testAcreate() {
            System.out.println("first");
        }
        @Test
        public void testBupdate() {
            System.out.println("second");
        }
        @Test
        public void testCdelete() {
            System.out.println("third");
        }
    }
    

提交回复
热议问题