指定dependsOnMethods时,testng未按优先级顺序运行 [英] testng not running in priority order when dependsOnMethods is specified

查看:583
本文介绍了指定dependsOnMethods时,testng未按优先级顺序运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我们在 @Test priority dependsOnMethods c>带注释的方法,测试方法的执行顺序不是根据优先级。为什么会这样?
以下是用于演示此问题的测试类:

Whenever we specify priority and dependsOnMethods on a @Test annotated method, the order of execution of test methods is not according to the priority. why is so? Here is the test class to demonstrate the issue:

package unitTest.TestNGTestCases;

import org.testng.annotations.Test;

public class TestNGTest1 {
    @Test(priority=1)
    public void t1()
    {
        System.out.println("Running 1");
    }
    @Test(priority=2,dependsOnMethods="t1")
    public void t2()
    {
        System.out.println("Running 2");
    }
    @Test(priority=3,dependsOnMethods="t2")
    public void t3()
    {
        System.out.println("Running 3");
    }
    @Test(priority=4)
    public void t4()
    {
        System.out.println("Running 4");
    }
}

实际产出:

Running 1
Running 4
Running 2
Running 3

===============================================
All Tests Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================

预期输出:

Running 1
Running 2
Running 3
Running 4

===============================================
All Tests Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================

测试执行的顺序应该是t1,t2,t3,t4。为什么t4在t1之后执行,当t2和t3的优先级高于t4?

The order of test execution should have been t1, t2, t3, t4. why is t4 getting executed after t1, when t2 and t3 have higher priority then t4?

TIA

推荐答案

首先执行所有独立方法(没有@dependsOnMethods依赖关系)。然后将执行具有依赖性的方法。如果执行顺序中存在歧义,即使在此订购之后,优先级也会出现。

All independent methods (that do not have @dependsOnMethods dependency) will be executed first. Then methods with dependency will be executed. If there is ambiguity in execution order even after this ordering, priority comes into picture.

这是订购方案:


  1. 执行所有独立方法(没有@dependsOnMethods注释的方法)

  2. 如果此排序存在歧义,则使用优先级来解决独立方法的歧义

  3. 按依赖顺序执行依赖方法

  4. 如果此排序存在歧义,则使用优先级来解决依赖方法的歧义

  5. 如果仍然存在歧义(由于未使用优先级或两种方法具有相同的优先级),请根据字母顺序对它们进行排序。

  1. Execute all independent methods (methods without @dependsOnMethods annotation)
  2. If there is ambiguity in this ordering use priority to resolve ambiguity for independent methods
  3. Execute dependent methods in order of dependency
  4. If there is ambiguity in this ordering use priority to resolve ambiguity for dependent methods
  5. If there is still ambiguity (due to not using priority or two methods having same priority) order them based on alphabetical order.

现在所有歧义都得到了解决,因为没有两种方法可以具有相同的名称。

Now all ambiguity is resolved since no two methods can have the same name.

这篇关于指定dependsOnMethods时,testng未按优先级顺序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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