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:
-
ExecutableInvoker
MethodInvoker
-
Field Summary
Modifier and TypeFieldDescriptionstatic final MethodInvoker
Shared instance of the defaultMethodInvoker
. -
Method Summary
-
Field Details
-
DEFAULT_INVOKER
Shared instance of the defaultMethodInvoker
.This invoker never provides arguments to a
Method
.
-
-
Method Details
-
invoke
Invoke the suppliedMethod
on the suppliedtarget
.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 registeredParameterResolvers
(such as theSpringExtension
).- Parameters:
method
- the method to invoketarget
- the object on which to invoke the method, may benull
if the method isstatic
- Returns:
- the value returned from the method invocation, potentially
null
- Throws:
Exception
- if any error occurs
-