java - allure2 监听器输出控制台中的步骤

标签 java testng allure

我正在将 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)的全名新建一个文件。
  • 将您的实现类的完整路径添加到此文件中。

您可以在以下项目中找到示例:https://github.com/sskorol/allure2-testng-report/blob/master/src/test/resources/META-INF/services/io.qameta.allure.listener.StepLifecycleListener

有关 SPI 的更多信息:http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html

关于java - allure2 监听器输出控制台中的步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45624859/

相关文章:

java - 如何在可执行 JAR 中加载 TestNG 配置?

Java 单元测试覆盖率数字不匹配

java - Selenium 中的数据提供者与 TestNG 不匹配

python - 深度定制 Allure 报告页面

java - 界面中需要澄清

java - Spring MVC 导致错误的操作

java - 如何使用Java执行Allure命令

java - 倾城:无法获得 ru.yandex.qat ools.allure 的报告:allure-maven-plugin

Java 贷款摊销

Java Bitshift 取代 Math.pow