Overview

In order to be able to support parameter injection in @BeforeTransaction and @AfterTransaction methods (see #30736), we need a generic mechanism for delegating to the underlying testing framework to invoke methods.

While we're at it, we could do the same for constructors, but I'm hesitant to add a feature that TestExecutionListener authors will never actually need.

In light of that, we should introduce an MethodInvoker API for TestExecutionListeners in the Spring TestContext Framework.

The default implementation should simply invoke the method without arguments.

A JUnit Jupiter specific implementation (registered in the SpringExtension) should delegate to the org.junit.jupiter.api.extension.ExtensionContext.getExecutableInvoker() mechanism introduced in JUnit Jupiter 5.9. This will allow a TestExecutionListener to transparently benefit from registered ParameterResolvers in JUnit Jupiter (including the SpringExtension) when invoking user methods, effectively providing support for parameter injection for arbitrary methods.

Related Issues

  • https://github.com/junit-team/junit5/issues/2393
  • https://github.com/junit-team/junit5/issues/2191
  • 30736