【问题标题】:Is there a way to preserve the order of tests in TestNG without a TestSuite.xml file?有没有办法在没有 TestSuite.xml 文件的情况下保留 TestNG 中的测试顺序?
【发布时间】:2013-08-28 22:03:20
【问题描述】:

我正在 TestNG 中进行 Selenium 测试。我不希望将所有测试方法保存在单独的文件中而带来维护烦恼,我宁愿只包含一个包来扫描@Tests。

在这种情况下,有没有办法在测试文件中保留测试方法的顺序,并让 TestNG 一次使用一个测试类。目前,我正在使用 @Test(dependsOn={}) 维护测试中的方法顺序,该方法有效;但是,我看到了这种情况

TestClassA

  • test_method_1
  • test_method_2
  • test_method_3
  • test_method_4

TestClassB

  • test_method_1
  • test_method_2
  • test_method_3
  • test_method_4

运行测试,顺序如下:

  • B 类,方法 1
  • A 类,方法 1
  • B 类,方法 2
  • B 类,方法 3
  • A 类,方法 2
  • A 类,方法 3
  • B 类,方法 4
  • A 类,方法 4

我不关心类的顺序,我只关心一个测试类的方法在进入下一个测试类之前完全运行。

有人吗?

【问题讨论】:

    标签: selenium testng


    【解决方案1】:

    很高兴看到您的 testng.xml 文件。这里似乎描述了类似的情况:http://testng.org/doc/documentation-main.html#testng-xml。我认为在你的情况下你应该有

    <class name="TestClassA">
      <methods>
        <include name="test_method_1" />
        <include name="test_method_2" />
        ...
      </methods>
    </class>
    
    <class name="TestClassB">
      <methods>
        <include name="test_method_1" />
        <include name="test_method_2" />
        ...
      </methods>
    

    【讨论】:

    • 不过就是这样,我想在没有 testng.xml 文件的情况下执行此操作 - 仅使用包扫描。最后,我完成了自己的类扫描并动态创建了一个 testng.xml 文件,该文件保留了测试类的顺序和完成,同时允许测试本身按设计无序。
    猜你喜欢
    • 2018-12-31
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 2021-04-08
    • 2021-09-24
    • 2017-01-10
    • 2020-08-31
    • 1970-01-01
    相关资源
    最近更新 更多