@API(value=Experimental) public interface TestExtensionContext extends ExtensionContext
TestExtensionContext encapsulates the context in which
the current test is being executed.ExtensionContext.Namespace, ExtensionContext.Store| Modifier and Type | Method and Description |
|---|---|
java.util.Optional<java.lang.Throwable> |
getTestException()
Get the exception that was thrown during execution of the test associated
with this
TestExtensionContext, if available. |
java.lang.Object |
getTestInstance()
Get the test instance associated with this
TestExtensionContext. |
getDisplayName, getElement, getParent, getStore, getStore, getTags, getTestClass, getTestMethod, getUniqueId, publishReportEntryjava.lang.Object getTestInstance()
TestExtensionContext.nulljava.util.Optional<java.lang.Throwable> getTestException()
TestExtensionContext, if available.
This method is typically used for logging and tracing purposes. If you
wish to actually handle an exception thrown during test execution,
implement the TestExecutionExceptionHandler API.
Unlike the exception passed to a TestExecutionExceptionHandler,
a test exception returned by this method can be any exception
thrown during the invocation of a @Test method, its surrounding
@BeforeEach and @AfterEach methods, or a test-level
Extension. Note, however, that this method will never return an
exception swallowed by a TestExecutionExceptionHandler.
Furthermore, if multiple exceptions have been thrown during test execution,
the exception returned by this method will be the first such exception with
all additional exceptions suppressed in the first one.
Optional containing the exception thrown; never
null but potentially empty if test execution has not (yet)
resulted in an exception