Junit-5 测试执行顺序

Junit-5 Test Execution Order

我正在编写自动化脚本以在真实设备上测试 iOS 应用程序。我正在使用 appium 服务器。我有一些与 Junit 测试用例执行相关的问题。我之前用 @order() 注解写了 9 个测试方法。像 1->9 。我将服务器功能放在第一个测试方法中。直到 9 种方法,执行都进行得很顺利。但是当我写 10 11 和 12 方法的时候。执行从第 10 个方法开始。如 10->11->12->1-> 依此类推直到 9.

这是代码

class TesClass {
 String appiumPort ="4723";
 String serverIp ="0.0.0.0";
 static IOSDriver<IOSElement> driver;
 LoginPage lPage=null;
 DesiredCapabilities cap;
 ProgrammesPage p_page=null;
 MainPage mPage=null;



 /*
  * Order is the priority of the test case
  * this is the first test case in this class
  * This is responsible for creating connection with the appium server
  * this sets basic capabilities and some advance capabilities 
  * to run the test cases on a real Ios device
  * 
  */
@Order(1)
@Test
void test() throws MalformedURLException  {
    cap= new DesiredCapabilities();


      cap.setCapability("deviceName", "Muhammad’s iPhone");
      cap.setCapability("platformName", "iOS");
      cap.setCapability("platformVersion","12.1.2");
      cap.setCapability("automationName", "XCUITest");
      cap.setCapability("app", "/Users/ahmsam/Downloads/MainApp-2.ipa");
      cap.setCapability("xcodeOrgId","BNL4VQ2576");
      cap.setCapability("xcodeSigningId","iPhone Developer");
      cap.setCapability("udid","240476512a6dd29a2f82fc8211ef4ea1bf6b5891");
     // cap.setCapability("udid","3c7ad82d510561a572d459cab855154cd578e3da");
      cap.setCapability("updateWDABundleId","5SN9XXLNWB.uk.org.humanfocus.WildCard.Dev");

      String serverUrl = "http://" + serverIp + ":" + appiumPort + "/wd/hub";
      driver = new IOSDriver<IOSElement>(new URL(serverUrl), cap);
      driver.manage().timeouts().implicitlyWait(55,TimeUnit.SECONDS);

      lPage=new LoginPage(driver);
      lPage.firstThreePopoClick();
      boolean check= lPage.validateLoginpage();

     // = lPage.loginTestCase();

     Assert.assertTrue(check);


     //fail("Not yet implemented");
}

 @Order(2)
 @Test
    void test1() 
    {
        lPage=new LoginPage(driver);

        boolean check1=lPage.TestdoLoginWIthValues();

        Assert.assertTrue(check1==true);

    }

 @Order(3)
 @Test
    void test3() 
    {
        lPage=new LoginPage(driver);

        boolean check1=lPage.loginTestCase();

        Assert.assertTrue(check1==true);

    }

 @Order(4)
 @Test
    void test4() 
    {
        lPage=new LoginPage(driver);

        boolean check1=lPage.TestGotoHomePage();

        Assert.assertTrue(check1==true);

    }

 @Order(5)
 @Test
    void test5() 
    {
        mPage=new MainPage(driver);


        boolean check1=mPage.goToTrainings();

        Assert.assertTrue(check1);

    }

 @Order(6)
 @Test
    void test6() 
    {
        p_page=new ProgrammesPage(driver);


        boolean check1=p_page.verifyProgramCode();

        Assert.assertTrue(check1);

    }

 @Order(7)
 @Test
    void test7() 
    {
        p_page=new ProgrammesPage(driver);
        boolean check1=p_page.verifyContinueBtnDisable();

        Assert.assertTrue(check1);

    }

 @Order(8)
 @Test
    void test8() 
    {
        p_page=new ProgrammesPage(driver);
        boolean check1=p_page.verifyVideoNextBtnDIsable();

        Assert.assertTrue(check1);

    }

 @Order(9)
 @Test
    void test9() throws InterruptedException 
    {
        p_page=new ProgrammesPage(driver);
        boolean check1=p_page.verifyWatchView_ClickonNextBtn();

        Assert.assertTrue(check1);

    }

 @Order(10)
 @Test
    void test10() 
    {
        p_page=new ProgrammesPage(driver);
        boolean check1=p_page.verifyDocumentPageNextButton();

        Assert.assertTrue(check1);

    }

 @Order(11)
 @Test
    void test11() 
    {
        p_page=new ProgrammesPage(driver);
        boolean check1=p_page.verifyViewDocument_NextBtn();

        Assert.assertTrue(check1);

    }

 @Order(12)
 @Test
    void test12() 
    {
        p_page=new ProgrammesPage(driver);
        boolean check1=p_page.verifyLastSectionName();

        Assert.assertTrue(check1);

    }

} enter image description here

使用 @TestMethodOrder 注释指定要使用的所需方法排序器实现,在本例中为 OrderAnnotation。将此注释添加到您的测试 class:@TestMethodOrder(MethodOrderer.OrderAnnotation.class)。喜欢:

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class TestClass {

    @Order(1)
    @Test
    void test() {
    ...