Interface TestExecutionExceptionHandler
- All Superinterfaces:
Extension
- All Known Implementing Classes:
ExpectedExceptionSupport
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
TestExecutionExceptionHandler defines the API for Extensions that wish to handle exceptions thrown during test execution.
In this context, test execution refers to the physical
invocation of a @Test method and not to any test-level extensions
or callbacks.
Common use cases include swallowing an exception if it's anticipated or rolling back a transaction in certain error scenarios.
Constructor Requirements
Consult the documentation in Extension for details on
constructor requirements.
- Since:
- 5.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidhandleTestExecutionException(ExtensionContext context, Throwable throwable) Handle the suppliedthrowable.
-
Method Details
-
handleTestExecutionException
Handle the suppliedthrowable.Implementors must perform one of the following.
- Swallow the supplied
throwable, thereby preventing propagation. - Rethrow the supplied
throwableas is. - Throw a new exception, potentially wrapping the supplied
throwable.
If the supplied
throwableis swallowed, subsequentTestExecutionExceptionHandlerswill not be invoked; otherwise, the next registeredTestExecutionExceptionHandler(if there is one) will be invoked with anyThrowablethrown by this handler.Note that the
execution exceptionin the suppliedExtensionContextwill not contain theThrowablethrown during invocation of the corresponding@Testmethod.- Parameters:
context- the current extension context; nevernullthrowable- theThrowableto handle; nevernull- Throws:
Throwable
- Swallow the supplied
-