@API(value=Experimental) public class ExpectedExceptionSupport extends Object implements AfterEachCallback, TestExecutionExceptionHandler
Extension
provides native support for the
ExpectedException
rule from JUnit 4.
By using this class-level extension on a test class,
ExpectedException
can continue to be used.
However, you should rather switch to
Assertions.assertThrows(java.lang.Class<T>, org.junit.jupiter.api.function.Executable)
for new code.
Assertions.assertThrows(java.lang.Class<T>, org.junit.jupiter.api.function.Executable)
,
ExpectedException
,
TestRule
,
Rule
Constructor and Description |
---|
ExpectedExceptionSupport() |
Modifier and Type | Method and Description |
---|---|
void |
afterEach(ExtensionContext context)
Callback that is invoked after each test has been invoked.
|
void |
handleTestExecutionException(ExtensionContext context,
Throwable throwable)
Handle the supplied
throwable . |
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable
TestExecutionExceptionHandler
throwable
.
Implementors must perform one of the following.
throwable
, thereby preventing propagation.throwable
as is.throwable
.If the supplied throwable
is swallowed, subsequent
TestExecutionExceptionHandlers
will not be invoked; otherwise,
the next registered TestExecutionExceptionHandler
(if there is
one) will be invoked with any Throwable
thrown by this handler.
Note that the execution
exception
in the supplied ExtensionContext
will not
contain the Throwable
thrown during invocation of the corresponding
@Test
method.
handleTestExecutionException
in interface TestExecutionExceptionHandler
context
- the current extension context; never null
throwable
- the Throwable
to handle; never null
Throwable
public void afterEach(ExtensionContext context) throws Exception
AfterEachCallback
afterEach
in interface AfterEachCallback
context
- the current extension context; never null
Exception