如何使用 junit 5 订购测试

How to order tests using junit 5

我在 java 中使用 appium 和 junit 5 创建了一些自动化测试。 我试图在每次测试前使用 @Order 注释来订购我的测试。 在测试 class 之前,我正在使用 @TestMethodOrder(MethodOrderer.OrderAnnotation.class).

但是还是没有下单。 在代码下方,您可以看到带有测试顺序的附件。 根据它的外观,它现在没有下任何订单。

Maven 依赖项:

<dependencies>
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.2.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.0-M1</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

Class 测试:

package Tests;

import AppiumBase.BaseTestClass;
import Components.DrawerNavigation;
import Components.RenewPolicy;
import Utils.CustomAnotations.Attributes;
import Utils.CustomScreenAction;
import com.sun.org.glassfish.gmbal.Description;
import org.junit.jupiter.api.*;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.core.annotation.Order;

import static Utils.CustomAnotations.Attributes.TEXT_VIEW;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@DisplayName("Renew policy functionality")
@Attributes
public class RenewPolicyTest extends BaseTestClass {

    private WebDriverWait wait;
    private DrawerNavigation drawerNavigation;
    private RenewPolicy renewPolicy;
    private CustomScreenAction csa;

    @BeforeEach
    void executeBeforeEachTestInThisClass() {
        wait = new WebDriverWait(driver(), 10);
        drawerNavigation = new DrawerNavigation(driver());
        renewPolicy = new RenewPolicy(driver());
        csa = new CustomScreenAction();
    }

    @AfterEach
    void executeAfterEachTestInThisClass() {
        wait = null;
        drawerNavigation = null;
        renewPolicy = null;
    }

    @Test
    @Order(1)
    @DisplayName("Check renew policy button")
    @Description("Verify that the renew policy button appear on main screen")
    void isButtonAppear() {
        renewPolicy.isRenewPolicyButtonAppearOnMainScreen();
    }

    @Test
    @Order(2)
    @DisplayName("Check renew policy screen is opens")
    @Description("Verify that the renew policy button on MAIN SCREEN is clickable and right screen is opens")
    void isRenewPolicyScreenAppear() {
        renewPolicy.clickOnRenewPolicyButton();
    }

    @Test
    @Order(3)
    @DisplayName("Check renew policy screen opens from side menu")
    @Description("Verify that the renew policy button on DRAWER NAVIGATION is clickable and right screen is opens")
    void isRenewPolicyScreenOpenOnClickButtonFromDN() {
        drawerNavigation.openSideMenu();
        drawerNavigation.openRenewPolicyScreen();
    }

    @Test
    @Order(4)
    @DisplayName("Check checkbox")
    @Description("Check that the checkbox is checkable")
    void isCheckBoxCheckable() {
        renewPolicy.clickOnRenewPolicyButton();
        if (renewPolicy.isRenewPolicyScreenOpens()) {
            CustomScreenAction csa = new CustomScreenAction();
            csa.scrollToElement(TEXT_VIEW, "לשינויים אפשר לפנות למוקד");
        }
        renewPolicy.checkCheckBox();
    }

    @Test
    @Order(5)
    @DisplayName("Check confirm and pay button - disabled")
    @Description("Verify that the button is disabled while checkbox not checked")
    void isButtonDisabled() {
        renewPolicy.clickOnRenewPolicyButton();
        if (renewPolicy.isRenewPolicyScreenOpens()) {
            csa.scrollToElement(TEXT_VIEW, "מאשר תשלום וחידוש פוליסה");
        }
        if (renewPolicy.isConfirmAndRenewPolicyButtonDisplay()) {
            csa.isElementDisabled(renewPolicy.getConfirmAndRenewPolicyButton());
        }
    }

    @Test
    @Order(6)
    @DisplayName("Check confirm and pay button - enabled")
    @Description("Verify that the button is enabled while checkbox checked")
    void isButtonEnabled() {
        renewPolicy.clickOnRenewPolicyButton();
        if (renewPolicy.isRenewPolicyScreenOpens()) {
            csa.scrollToElement(TEXT_VIEW, "מאשר תשלום וחידוש פוליסה");
        }
        renewPolicy.checkCheckBox();
        if (renewPolicy.isConfirmAndRenewPolicyButtonDisplay()) {
            csa.isElementEnabled(renewPolicy.getConfirmAndRenewPolicyButton());
        }
    }
}

输出:

您的导入有误,请将 import org.springframework.core.annotation.Order; 替换为 import org.junit.jupiter.api.Order;