Choose order to execute JUnit tests

后端 未结 8 1042
执笔经年
执笔经年 2020-12-11 03:32

I wanted to choose the order to execute the JUnit tests. I have 4 classes with several test methods in it, my goal is to execute, for instance, method Y of class A, then met

8条回答
  •  隐瞒了意图╮
    2020-12-11 03:58

    From version 4.11 you can specify execution order using annotations and ordering by method name:

    import org.junit.Test;
    import org.junit.FixMethodOrder;
    import org.junit.runners.MethodSorters;
    
    @FixMethodOrder(MethodSorters.NAME_ASCENDING)
    public class MyTest {
    
        @Test
        public void test1Create() {
            System.out.println("first");
        }
    
        @Test
        public void test2Update() {
            System.out.println("second");
        }
    }
    

    See JUnit 4.11 Release Notes

提交回复
热议问题