Interface MethodInvoker


public interface MethodInvoker
MethodInvoker defines a generic API for invoking a Method within the Spring TestContext Framework.

Specifically, a MethodInvoker is made available to a TestExecutionListener via TestContext.getMethodInvoker(), and a TestExecutionListener can use the invoker to transparently benefit from any special method invocation features of the underlying testing framework.

For example, when the underlying testing framework is JUnit Jupiter, a TestExecutionListener can use a MethodInvoker to invoke arbitrary methods with JUnit Jupiter's parameter resolution mechanism. For other testing frameworks, the DEFAULT_INVOKER will be used.

Since:
6.1
Author:
Sam Brannen
See Also:
  • Field Details

  • Method Details

    • invoke

      @Nullable Object invoke(Method method, @Nullable Object target) throws Exception
      Invoke the supplied Method on the supplied target.

      When the DEFAULT_INVOKER is used — for example, when the underlying testing framework is JUnit 4 or TestNG — the method must not declare any formal parameters. When the underlying testing framework is JUnit Jupiter, parameters will be dynamically resolved via registered ParameterResolvers (such as the SpringExtension).

      Parameters:
      method - the method to invoke
      target - the object on which to invoke the method, may be null if the method is static
      Returns:
      the value returned from the method invocation, potentially null
      Throws:
      Exception - if any error occurs