【问题标题】:JUnit 5: Is it possible to set a TestExecutionListener in Maven Surefire Plugin?JUnit 5:是否可以在 Maven Surefire 插件中设置 TestExecutionListener?
【发布时间】:2018-09-30 22:10:08
【问题描述】:

我想在测试运行完成后使用 JUnit 5 和TestExecutionListener 接口进行一些清理工作。整个项目使用 JUnit Jupiter,不涉及 Vintage。

在 Maven Surefire 中,它能够通过配置设置 JUnit 4 RunListener 来存档它。 Surefire 是否能够识别新的 JUnit 5 TestExecutionListener?如果没有,有没有办法让 JUnit 5 测试并使用 TestExecutionListenerRunListener

我不想创建自己的启动器只是为了使用侦听器执行测试。

【问题讨论】:

    标签: java maven junit maven-surefire-plugin junit5


    【解决方案1】:

    Maven Surefire 目前不支持通过其配置添加TestExecutionListener。我认为您应该为他们打开一个问题,因为他们目前正在将 JUnit 团队的自定义提供程序合并到他们的代码库中。

    但是,您可以通过User Guide 中描述的服务加载器机制注册您的自定义TestExecutionListener

    【讨论】:

    • 感谢您的回答。不知何故,我错过了用户指南中的这一段。对于像我一样不熟悉 Service Loader 机制的每个人,试试 Google AutoService 库:github.com/google/auto/tree/master/service
    • 没有办法在屏幕上干净地打印一些东西,是吗?从 ServiceLoader-loaded TestExecutionListener 无法访问 Maven 记录器。
    • 是否有一些静态方法可以访问 Maven 记录器?
    猜你喜欢
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    相关资源
    最近更新 更多