【问题标题】:How to order tests using junit 5如何使用junit 5订购测试
【发布时间】:2020-04-20 12:24:23
【问题描述】:

我使用 appium 和 junit 5 在 java 中创建了一些自动化测试。 我正在尝试在每次测试之前使用 @Order 注释订购我的测试。 在测试课之前,我使用的是@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>

带测试的类:

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

输出:

【问题讨论】:

  • 我可以看到测试的排序方式与您使用 @Order 标记的方式相同。你的期望是什么?
  • 从第 1 行发布完整的测试代码(因此包括导入语句)。
  • 您在两个测试中设置了 @Order(1)Check renew policy buttonCheck checkbox
  • 嗨@JBNizet,我用完整的代码更新了这个问题。请参见。还更改检查复选框的订单号,但仍然无法正常工作
  • 现在看看导入:JUnit 是否会依赖来自 Spring 框架的注解,从而迫使 JUnit 的每个用户也使用 Spring,而不是使用自己的?

标签: java junit appium


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-06-08
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    相关资源
    最近更新 更多