简体   繁体   English

如何使用junit 5订购测试

[英]How to order tests using junit 5

I'm Created some automation test in java , using appium and junit 5. I'm trying to Order my test with @Order annotation before each test.我在 java 中创建了一些自动化测试,使用 appium 和 junit 5。我试图在每次测试之前使用@Order注释对我的测试进行@Order And before test class I'm using @TestMethodOrder(MethodOrderer.OrderAnnotation.class) .在测试课程之前,我正在使用@TestMethodOrder(MethodOrderer.OrderAnnotation.class)

But it still not ordered.但它仍然没有订购。 Below the code you can see attachment with tests order.在代码下方,您可以看到带有测试顺序的附件。 Based on what it looks like, it doesn't make any order right now.根据它的样子,它现在不会下任何订单。

Maven dependencies: 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 with tests:带测试的类:

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());
        }
    }
}

Output:输出: 在此处输入图片说明

Your import is wrong, replace import org.springframework.core.annotation.Order;你的导入有误,替换import org.springframework.core.annotation.Order; with import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM