public class ExpectedExceptionExtension extends Object implements org.junit.jupiter.api.extension.TestExecutionExceptionHandler
ExpectedException annotation to a test method.
Usage example:
public class MyTest {
@Test
@ExpectedException(type = Exception.class, messageIs = "Boom!")
public void canHandleAnException() throws Exception {
// ...
throw new Exception("Boom!");
}
@Test
@ExpectedException(type = RuntimeException.class, messageStartsWith = "Bye")
public void canHandleAnExceptionWithAMessageWhichStartsWith() {
// ...
throw new RuntimeException("Bye bye");
}
}
| Constructor and Description |
|---|
ExpectedExceptionExtension() |
| Modifier and Type | Method and Description |
|---|---|
void |
handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext extensionContext,
Throwable throwable)
Handle the supplied
Throwable throwable. |
public void handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext extensionContext,
Throwable throwable)
throws Throwable
Throwable throwable. If the extensionContext is annotated
with ExpectedException and if the throwable matches the expectations expressed
in the ExpectedException annotation then the supplied throwable is swallowed
otherwise the supplied throwable is rethrown.handleTestExecutionException in interface org.junit.jupiter.api.extension.TestExecutionExceptionHandlerextensionContext - the current extension contextthrowable - the Throwable to handleThrowableCopyright © 2017. All rights reserved.