gpt4 book ai didi

java - 为什么 TestNG 优先级功能未按预期顺序运行

转载 作者:行者123 更新时间:2023-12-01 19:35:32 26 4
gpt4 key购买 nike

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

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 是如何工作的?

最佳答案

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

All the methods you depend on must have run and succeeded for you to run

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

TestCaseOne() 具有下一个最高优先级 (4),没有依赖性 -> 它运行第二

TestCaseSecond() 具有最高优先级,满足所有依赖项(TestCaseOne 运行) -> 它运行第三

TestCaseThird() 具有最高优先级,满足所有依赖项(TestCaseSecond 运行) -> 它运行第四

关于java - 为什么 TestNG 优先级功能未按预期顺序运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57800687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com