如何使测试运行在TestNG测试套件中持续运行

huangapple go评论74阅读模式
英文:

How to make a test run last in a TestNG tests suite

问题

我正在项目中使用 TestNG 进行功能测试,我需要确保特定的测试在最后运行。###

我尝试过使用依赖关系并通过这些依赖关系建立“线性”执行流程,但是这个解决方案有点低效,因为有些测试实际上可以在不必确保另一个测试在执行之前已通过的情况下运行。

因此,依赖性的主要问题是,如果执行中的一个测试失败,TestNG 就不会执行其余的测试,我不希望出现这种行为。

此外,我需要测试套件的顺序不是线性的,例如:Test 1 -> Test 2 -> ... -> Test n

实际上,我的顺序更像是一棵树:

  • Test 1
  • Test 2 -> 依赖于 1
  • Test 3 -> 依赖于 1
  • Test 4 -> 依赖于 3
  • Test 5 -> 依赖于 4
  • Test 6 -> 依赖于 1 和 3
  • Test 7 -> 依赖于 2 和 6
  • Test -> 依赖于 3(这个应该作为最后一个执行)

(上面的示例是假设的,只是试图描述我的测试场景)

我尝试过使用优先级,但它们似乎不像这样工作。您对此有什么建议吗?感谢您的帮助,对于这个初学者的问题我感到抱歉。

英文:

I am using TestNG for functional testing in my project and I need to ensure a specific test run the last.

I tried using dependencies and establishing a "lineal" flow of execution through those dependencies, but this solution was a little bit inefficient since there are tests that actually can run without having to ensure another test passed before they are being executed.

So, the main problem with dependencies is if a test fails in the execution, TestNG doesn't execute the rest of them and I don't want this behavior.

Also, the order I need for my test suite is not lineal, for example: Test 1 -> Test 2 -> ... -> Test n

Actually, my ordering is more like a tree:

  • Test 1
  • Test 2 -> depends on 1
  • Test 3 -> depends on 1
  • Test 4 -> depends on 3
  • Test 5 -> depends on 4
  • Test 6 -> depends on 1 and 3
  • Test 7 -> depends on 2 and 6
  • Test -> depends on 3 (this one should be executed as the last)

(Above example is hypothetical and only tries to describe my test scenario)

I tried using priorities but they seem not to work like this. Do you have a recommendation about this guys? Thank you for your help and sorry for the noob question.

答案1

得分: 1

在这种情况下,您可以将优先级与依赖项混合使用:在此处查看教程

英文:

In this case, you can mix priority with depends on: Check here a tutorial

huangapple
  • 本文由 发表于 2020年8月29日 06:37:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63641681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定