TestNG 优先执行测试用例的顺序 [英] TestNG order of Test Case execution with priority

查看:55
本文介绍了TestNG 优先执行测试用例的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The following are the test methods in TestNG test case class:

@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

The execution order is test01 - test03 - test04 - test02. Well this seems incorrect, because, by the time test02 is reached, the dependent test method test01 is already executed. Hence the test02 should get executed immediately. The correct order, I feel, is test01 - test02 - test03 - test04

这是 TestNG 中的一个错误,还是由于某些特殊原因我遗漏了这一点?

Is this a bug in the TestNG or is this deliberate for some particular reason that I am missing ?

推荐答案

不要提供优先级和依赖项,可以将测试分组.你可以这样做:

Don't provide priority and depends on together, you can group the tests. You can do it like :

@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");
}

这篇关于TestNG 优先执行测试用例的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆