【问题标题】:Excecute a method only once for suite of suites testng xml file仅对套件 testng xml 文件执行一次方法
【发布时间】:2019-03-26 16:55:45
【问题描述】:

有没有办法在 testng 套件文件中的所有套件完成后运行方法(如 @AfterSuite)?

例如,考虑这个 testng xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" preserve-order="true" thread-count="5">
<suite name="TestNG example suite"  > 
<!-- suite name="Suite Name" --> 
        <suite-files>
               <suite-file path="./suiteA.xml" />
               <suite-file path="./suiteB.xml" />
               <suite-file path="./suiteC.xml" />
        </suite-files>
</suite>

我只想在 suiteC.xml 完成后执行一些操作(如下载日志),即在所有套件完成后。

【问题讨论】:

  • 如何实现您自己的ISuiteListener 并在onFinish() 方法中添加您的自定义登录(some more samples)?
  • 这似乎不起作用。 onFinish() 在每个套件之后调用。我想要的是在父套件启动之前调用一个方法,在父套件完成后调用另一个方法。套件文件可以是一套套件。

标签: java testng


【解决方案1】:

解决方案是实现自己的 IExecutionListener。

IExecutionListener 有两个方法,onExecutionStart() 和 onExecutionFinish()。在 TestNG 开始运行套件之前调用 onExecutionStart() 方法,并且在运行所有套件后运行 onExecutionFinish()。

参考:

https://www.javarticles.com/2015/04/testng-iexecutionlistener-example.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 2019-01-08
    相关资源
    最近更新 更多