JUnit 5: Is it possible to set a TestExecutionListener in Maven Surefire Plugin?
Asked Answered
E

1

4

I want to use JUnit 5 and the TestExecutionListener interface to do some clean up after the test run is done. The whole project is using JUnit Jupiter, no Vintage involved.

In Maven Surefire it was able to set a JUnit 4 RunListener via configuration to archive this. Is Surefire able to recognize the new JUnit 5 TestExecutionListener? If not, is there any way to have JUnit 5 tests and use the TestExecutionListener or RunListener?

I do not want to create my own Launcher just to execute tests with the listener.

Elis answered 20/4, 2018 at 8:35 Comment(0)
B
8

Maven Surefire does currently not support adding a TestExecutionListener via its configuration. I think you should open an issue for them because they are currently incorporating the JUnit team's custom provider into their codebase.

However, you can register your custom TestExecutionListener via the Service Loader mechanism described in the User Guide.

Bohannon answered 20/4, 2018 at 9:54 Comment(3)
Thank you for your answer. Somehow I missed this paragraph in the user guide. For everybody who is not familiar with the Service Loader mechanism, like me, try the Google AutoService library: github.com/google/auto/tree/master/serviceElis
There is not way to cleanly print something on screen, is there? From the ServiceLoader-loaded TestExecutionListener there is no access to the Maven logger.Damiendamietta
Is there some static way to access the Maven logger?Bohannon

© 2022 - 2024 — McMap. All rights reserved.