【问题标题】:Why TestNG priority feature is not running in their expected order为什么 TestNG 优先级功能未按预期顺序运行
【发布时间】:2020-01-08 01:45:12
【问题描述】:

我已经确定了我的测试用例的优先级,但它们没有按优先级顺序运行?请参考下面的代码。

public class TestngFeature {

    WebDriver driver;

    @Test(priority = 4, invocationCount = 5, alwaysRun = true, enabled = true)
    public void TestCaseOne() {
        System.out.println("TestCaseFirst -- This is First Test Case");
        System.out.println("TestCaseOne -- This is first Test Case");
    }

    @Test(priority = 2, invocationTimeOut = 5, dependsOnMethods = "TestCaseOne")
    public void TestCaseSecond() {
        System.out.println("TestCaseSecond -- This is Second Test Case");
    }

    @Test(priority = 1, groups = { "Regression", "Smoke" }, dependsOnMethods = "TestCaseSecond")
    public void TestCaseThird() {
        System.out.println("TestCaseThird -- This is Third Test Case");
    }

    @Test(priority = 3, groups = { "Regression", "Sanity" })
    public void TestCaseFourth() {
        System.out.println("TestCaseFourth -- This is Fourth Test Case");
    }

    @Test(dependsOnGroups = "Regression")
    public void TestCaseFifth() {
        System.out.println("TestCaseFifth -- This is Fifth Test Case");
    }
}

输出:

[RemoteTestNG] detected TestNG version 6.14.3

TestCaseFourth -- This is Fourth Test Case

TestCaseFirst -- This is First Test Case

TestCaseOne -- This is first Test Case

TestCaseFirst -- This is First Test Case

TestCaseOne -- This is first Test Case

TestCaseFirst -- This is First Test Case

TestCaseOne -- This is first Test Case

TestCaseFirst -- This is First Test Case

TestCaseOne -- This is first Test Case

TestCaseFirst -- This is First Test Case

TestCaseOne -- This is first Test Case

TestCaseSecond -- This is Second Test Case

TestCaseThird -- This is Third Test Case

TestCaseFifth -- This is Fifth Test Case

PASSED: TestCaseFourth

PASSED: TestCaseOne

PASSED: TestCaseOne

PASSED: TestCaseOne

PASSED: TestCaseOne

PASSED: TestCaseOne

PASSED: TestCaseSecond

PASSED: TestCaseThird

PASSED: TestCaseFifth

===============================================
    Default test
    Tests run: 9, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 9, Failures: 0, Skips: 0
===============================================

这就是我得到的结果。为什么它不遵循优先级或优先级如何为 TestNG 工作?

【问题讨论】:

    标签: java selenium selenium-webdriver automation testng


    【解决方案1】:

    因为您为TestCaseSecondTestCaseThird 定义了dependsOnMethods。它优先于priority 属性。来自testng Dependencies with annotations

    您所依赖的所有方法都必须已运行并成功才能运行

    TestCaseFourth 具有最高优先级 (3),没有依赖关系 -> 它首先运行。

    TestCaseOne() 具有次高优先级 (4),没有依赖关系 -> 它运行在第二个

    TestCaseSecond() 在满足所有依赖项的情况下具有最高优先级(TestCaseOne 运行)-> 它运行在第三位

    TestCaseThird() 在满足所有依赖项的情况下具有最高优先级(TestCaseSecond 运行)-> 它运行在第四位

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 2020-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多