我正在将 Allure2 与 TestNG 结合使用。我想编写自己的监听器,在控制台输出中打印@Steps。
我在 allure 中看到了“StepLifecycleListener”接口(interface),但我无法在 TestNg 中实现这个监听器。有什么指点吗?
@Override
public void beforeStepStart(final StepResult result) {
System.out.format("Starting step: %s", result.getName());
}
@Override
public void afterStepStop(final StepResult result) {
System.out.format("Completed step: %s", result.getName());
}
最佳答案
Allure 2 监听器由 SPI 机制管理。因此,您需要执行几个步骤才能使其正常工作:
- 实现
StepLifecycleListener
接口(interface)并覆盖所需的方法。 - 在项目的
resources
根目录中创建META-INF/services
文件夹。 - 在上面的文件夹中用这个接口(interface)的全名新建一个文件。
- 将您的实现类的完整路径添加到此文件中。
有关 SPI 的更多信息:http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html
关于java - allure2 监听器输出控制台中的步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45624859/