@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 |
---|---|
Optional<Throwable> |
getTestException()
Get the exception that was thrown during execution of the test associated
with this
TestExtensionContext , if available. |
Object |
getTestInstance()
Get the test instance associated with this
TestExtensionContext . |
getDisplayName, getElement, getParent, getStore, getStore, getTags, getTestClass, getTestMethod, getUniqueId, publishReportEntry, publishReportEntry
Object getTestInstance()
TestExtensionContext
.null
Optional<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