How do I define an order to run junit tests in Intellij?

后端 未结 3 2064
北恋
北恋 2021-01-04 08:24

I have a flaky junit test that only fails if I run all my tests. I think that one test is causing another test to fail, I want to prove it before I try to fix it.

I

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 09:12

    As said by Ali Dehghani, You can order the test method execution by

    @FixMethodOrder(MethodSorters.NAME_ASCENDING): Sorts the test methods by method name, in lexicographic order.

    Code:

    @FixMethodOrder(MethodSorters.NAME_ASCENDING)
    public class ApplicationTest extends ActivityInstrumentationTestCase2 {
    
        public ApplicationTest() {
            super(MainActivity.class);
        }
    
        @Rule
        public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
    
        @Test
        void t1AttachUI(){
            // testing code goes here
        }
    
        @Test
        void t2InitializeViews(){
            // testing code goes here
        };
    
        @Test
        void t3SettingValues(){
            // testing code goes here
        };
    
        @Test
        void t4Validation(){
            // testing code goes here
        };
    
        @Test
        void t3AfterButtonPress(){
            // testing code goes here
        };
    }
    

提交回复
热议问题