How to run test methods in order with Junit

后端 未结 4 1792
一生所求
一生所求 2021-01-12 04:34

I am using JUnit and Selenium Webdriver. I want to run my test methods in order as how I write them in my code, as below:

@Test
public void registerUserTest(         


        
4条回答
  •  迷失自我
    2021-01-12 05:08

    Use the following command above the class from which you will execute your tests

    @FixMethodOrder(MethodSorters.JVM)
    public class TestMethodOrder {
    
        @Test
        public void signup() {
            System.out.println("Signup");
        }
    
        @Test
        public void login() {
            System.out.println("Login");
        }
    
        @Test
        public void navigate() {
            System.out.println("Navigate");
        }
    }
    

    The MethodSorters.JVM annotation will execute your tests in the way that you have actually written in your file. (Just as the same way that Java code executes, line by line)

提交回复
热议问题