gpt4 book ai didi

java - 具有优先级的测试用例执行的 TestNG 顺序

转载 作者:搜寻专家 更新时间:2023-11-01 03:56:31 26 4
gpt4 key购买 nike

TestNG测试用例类中的测试方法如下:

@Test (priority=0)
public void test01() {
}
@Test (priority=1, dependsOnMethods="test01")
public void test02() {
}
@Test (priority=2)
public void test03() {
}
@Test (priority=3)
public void test04() {
}

执行顺序是test01 - test03 - test04 - test02。嗯,这似乎是不正确的,因为在到达 test02 时,相关测试方法 test01 已经执行。因此 test02 应该立即执行。我觉得正确的顺序是 test01 - test02 - test03 - test04

这是 TestNG 中的一个 bug 还是出于我遗漏的某些特定原因故意设计的?

最佳答案

不要同时提供优先级和依赖,可以分组测试。你可以这样做:

@Test(priority = 1, groups = { "qty" })
public void increaseQty() {
System.out.println("in increase qty");
}

@Test(dependsOnMethods = { "increaseQty" }, groups = { "qty" })
public void decreaseQty() {
System.out.println("in decrease qty");
}

@Test(dependsOnGroups = { "qty" })
public void removeFromCart() throws Exception {
System.out.println("remove qty");
}

@Test(dependsOnMethods = { "removeFromCart" })
public void emptyCart() throws InterruptedException {
System.out.println("empty Cart");
}

关于java - 具有优先级的测试用例执行的 TestNG 顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39330510/

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