Module org.junit.jupiter.api
Package org.junit.jupiter.api.extension
Interface InvocationInterceptor
- All Superinterfaces:
Extension
InvocationInterceptor defines the API for Extensions that wish to intercept calls to test code.
Invocation Contract
Each method in this class must call InvocationInterceptor.Invocation.proceed() or InvocationInterceptor.Invocation.skip() exactly once on the supplied invocation. Otherwise, the
enclosing test or container will be reported as failed.
The default implementation calls proceed() on the supplied invocation.
Constructor Requirements
Consult the documentation in Extension for details on
constructor requirements.
- Since:
- 5.5
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn invocation that returns a result and may throw aThrowable. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidinterceptAfterAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of an@AfterAllmethod.default voidinterceptAfterEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of an@AfterEachmethod.default voidinterceptBeforeAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@BeforeAllmethod.default voidinterceptBeforeEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@BeforeEachmethod.default voidinterceptDynamicTest(InvocationInterceptor.Invocation<Void> invocation, DynamicTestInvocationContext invocationContext, ExtensionContext extensionContext) Intercept the invocation of aDynamicTest.default voidinterceptDynamicTest(InvocationInterceptor.Invocation<Void> invocation, ExtensionContext extensionContext) Deprecated.default <T> TinterceptTestClassConstructor(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Constructor<T>> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a test class constructor.default <T> TinterceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@TestFactorymethod, such as a@RepeatedTestor@ParameterizedTestmethod.default voidinterceptTestMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@Testmethod.default voidinterceptTestTemplateMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) Intercept the invocation of a@TestTemplatemethod.
-
Method Details
-
interceptTestClassConstructor
default <T> T interceptTestClassConstructor(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Constructor<T>> invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of a test class constructor.Note that the test class may not have been initialized (static initialization) when this method is invoked.
- Type Parameters:
T- the result type- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Returns:
- the result of the invocation; never
null - Throws:
Throwable- in case of failure
-
interceptBeforeAllMethod
default void interceptBeforeAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of a@BeforeAllmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
Throwable- in case of failures
-
interceptBeforeEachMethod
default void interceptBeforeEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of a@BeforeEachmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
Throwable- in case of failures
-
interceptTestMethod
default void interceptTestMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of a@Testmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
Throwable- in case of failures
-
interceptTestFactoryMethod
default <T> T interceptTestFactoryMethod(InvocationInterceptor.Invocation<T> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of a@TestFactorymethod, such as a@RepeatedTestor@ParameterizedTestmethod.- Type Parameters:
T- the result type- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Returns:
- the result of the invocation; potentially
null - Throws:
Throwable- in case of failures
-
interceptTestTemplateMethod
default void interceptTestTemplateMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of a@TestTemplatemethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
Throwable- in case of failures
-
interceptDynamicTest
@Deprecated @API(status=DEPRECATED, since="5.8") default void interceptDynamicTest(InvocationInterceptor.Invocation<Void> invocation, ExtensionContext extensionContext) throws Throwable Deprecated.Intercept the invocation of aDynamicTest.- Parameters:
invocation- the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
Throwable- in case of failures
-
interceptDynamicTest
@API(status=STABLE, since="5.11") default void interceptDynamicTest(InvocationInterceptor.Invocation<Void> invocation, DynamicTestInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of aDynamicTest.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
Throwable- in case of failures
-
interceptAfterEachMethod
default void interceptAfterEachMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of an@AfterEachmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
Throwable- in case of failures
-
interceptAfterAllMethod
default void interceptAfterAllMethod(InvocationInterceptor.Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable Intercept the invocation of an@AfterAllmethod.- Parameters:
invocation- the invocation that is being intercepted; nevernullinvocationContext- the context of the invocation that is being intercepted; nevernullextensionContext- the current extension context; nevernull- Throws:
Throwable- in case of failures
-
interceptDynamicTest(Invocation, DynamicTestInvocationContext, ExtensionContext)instead