@API(value=Internal) public final class MethodBasedTestExtensionContext extends java.lang.Object implements TestExtensionContext
ExtensionContext.Namespace, ExtensionContext.Store
Constructor and Description |
---|
MethodBasedTestExtensionContext(ExtensionContext parent,
EngineExecutionListener engineExecutionListener,
MethodTestDescriptor testDescriptor,
java.lang.Object testInstance,
ThrowableCollector throwableCollector) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDisplayName()
Get the display name for the current test or container.
|
java.util.Optional<java.lang.reflect.AnnotatedElement> |
getElement()
Get the
AnnotatedElement corresponding to the current extension
context, if available. |
java.util.Optional<ExtensionContext> |
getParent()
Get the parent extension context, if available.
|
ExtensionContext.Store |
getStore(ExtensionContext.Namespace namespace)
Get the
ExtensionContext.Store for the supplied ExtensionContext.Namespace . |
java.util.Set<java.lang.String> |
getTags()
Get the set of all tags for the current test or container.
|
java.util.Optional<java.lang.Class<?>> |
getTestClass()
Get the
Class associated with the current test or container,
if available. |
protected T |
getTestDescriptor() |
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 . |
java.util.Optional<java.lang.reflect.Method> |
getTestMethod()
Get the
Method associated with the current test, if available. |
java.lang.String |
getUniqueId()
Get the unique ID of the current test or container.
|
void |
publishReportEntry(java.util.Map<java.lang.String,java.lang.String> values)
Publish a map of key-value pairs to be consumed by an
org.junit.platform.engine.EngineExecutionListener . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getParent, getStore, getStore, getTags, publishReportEntry
public MethodBasedTestExtensionContext(ExtensionContext parent, EngineExecutionListener engineExecutionListener, MethodTestDescriptor testDescriptor, java.lang.Object testInstance, ThrowableCollector throwableCollector)
public java.lang.String getUniqueId()
ExtensionContext
getUniqueId
in interface ExtensionContext
null
or blankpublic java.lang.String getDisplayName()
ExtensionContext
The display name is either a default name or a custom name configured
via @DisplayName
.
For details on default display names consult the Javadoc for
TestInfo.getDisplayName()
.
Note that display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.
getDisplayName
in interface ExtensionContext
null
or blankpublic java.util.Optional<java.lang.reflect.AnnotatedElement> getElement()
ExtensionContext
AnnotatedElement
corresponding to the current extension
context, if available.
For example, if the current extension context encapsulates a test
class or test method, the annotated element will be the corresponding
Class
or Method
reference.
Favor this method over more specific methods whenever the
AnnotatedElement
API suits the task at hand — for example,
when looking up annotations regardless of concrete element type.
getElement
in interface ExtensionContext
Optional
containing the AnnotatedElement
;
never null
but potentially emptyExtensionContext.getTestClass()
,
ExtensionContext.getTestMethod()
public java.util.Optional<java.lang.Class<?>> getTestClass()
ExtensionContext
Class
associated with the current test or container,
if available.getTestClass
in interface ExtensionContext
Optional
containing the class; never null
but
potentially emptypublic java.util.Optional<java.lang.reflect.Method> getTestMethod()
ExtensionContext
Method
associated with the current test, if available.getTestMethod
in interface ExtensionContext
Optional
containing the method; never null
but
potentially emptypublic java.lang.Object getTestInstance()
TestExtensionContext
TestExtensionContext
.getTestInstance
in interface TestExtensionContext
null
public java.util.Optional<java.lang.Throwable> getTestException()
TestExtensionContext
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.
getTestException
in interface TestExtensionContext
Optional
containing the exception thrown; never
null
but potentially empty if test execution has not (yet)
resulted in an exceptionpublic void publishReportEntry(java.util.Map<java.lang.String,java.lang.String> values)
ExtensionContext
org.junit.platform.engine.EngineExecutionListener
.publishReportEntry
in interface ExtensionContext
values
- the key-value pairs to be published; never null
;
keys and values within entries in the map also must not be
null
or blankpublic java.util.Optional<ExtensionContext> getParent()
ExtensionContext
getParent
in interface ExtensionContext
Optional
containing the parent; never null
but
potentially emptyprotected T getTestDescriptor()
public ExtensionContext.Store getStore(ExtensionContext.Namespace namespace)
ExtensionContext
ExtensionContext.Store
for the supplied ExtensionContext.Namespace
.getStore
in interface ExtensionContext
namespace
- the Namespace
to get the store for; never null
null
public java.util.Set<java.lang.String> getTags()
ExtensionContext
Tags may be declared directly on the test element or inherited from an outer context.
getTags
in interface ExtensionContext
null
but
potentially empty