@API(value=Experimental) public interface ExtensionContext
ExtensionContext encapsulates the context in which the
current test or container is being executed.
Extensions are provided an instance of
ExtensionContext to perform their work.
ExtensionContext.Store,
ExtensionContext.Namespace| Modifier and Type | Interface and Description |
|---|---|
static class |
ExtensionContext.Namespace
A
Namespace is used to provide a scope for data saved by
extensions within a ExtensionContext.Store. |
static interface |
ExtensionContext.Store
Store provides methods for extensions to save and retrieve data. |
| 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.
|
default ExtensionContext.Store |
getStore()
Get the
ExtensionContext.Store for the default, global ExtensionContext.Namespace. |
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. |
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> map)
Publish a map of key-value pairs to be consumed by an
org.junit.platform.engine.EngineExecutionListener. |
java.util.Optional<ExtensionContext> getParent()
Optional containing the parent; never null but
potentially emptyjava.lang.String getUniqueId()
null or blankjava.lang.String getDisplayName()
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.
null or blankjava.util.Set<java.lang.String> getTags()
Tags may be declared directly on the test element or inherited from an outer context.
null but
potentially emptyjava.util.Optional<java.lang.reflect.AnnotatedElement> getElement()
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.
Optional containing the AnnotatedElement;
never null but potentially emptygetTestClass(),
getTestMethod()java.util.Optional<java.lang.Class<?>> getTestClass()
Class associated with the current test or container,
if available.Optional containing the class; never null but
potentially emptyjava.util.Optional<java.lang.reflect.Method> getTestMethod()
Method associated with the current test, if available.Optional containing the method; never null but
potentially emptyvoid publishReportEntry(java.util.Map<java.lang.String,java.lang.String> map)
org.junit.platform.engine.EngineExecutionListener.map - the key-value pairs to be published; never null;
keys and values within entries in the map also must not be
null or blankdefault ExtensionContext.Store getStore()
ExtensionContext.Store for the default, global ExtensionContext.Namespace.Store; never nullgetStore(Namespace),
ExtensionContext.Namespace.DEFAULTExtensionContext.Store getStore(ExtensionContext.Namespace namespace)
ExtensionContext.Store for the supplied ExtensionContext.Namespace.namespace - the Namespace to get the store for; never nullnull