@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.
| Modifier and Type | Interface and Description |
|---|---|
static class |
ExtensionContext.Namespace
Instances of this class are used to give saved data in extensions a scope, so that
extensions won't accidentally mix up data across each other or across different invocations
within their lifecycle.
|
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.lang.reflect.AnnotatedElement |
getElement()
Get the
AnnotatedElement corresponding to the current extension
context. |
java.lang.String |
getName()
Get the name for the current test or container.
|
java.util.Optional<ExtensionContext> |
getParent()
Get the parent extension context if there is one.
|
default ExtensionContext.Store |
getStore()
Get a
ExtensionContext.Store with the default ExtensionContext.Namespace. |
ExtensionContext.Store |
getStore(ExtensionContext.Namespace namespace)
Get a
ExtensionContext.Store for a self constructed ExtensionContext.Namespace. |
java.lang.Class<?> |
getTestClass()
Get the
Class associated with the current test or container. |
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 values to be consumed by an
org.junit.gen5.engine.EngineExecutionListener. |
java.util.Optional<ExtensionContext> getParent()
java.lang.String getUniqueId()
java.lang.String getName()
The name is typically a technical name of the underlying artifact — for example, the fully qualified name of a Java class, the canonical absolute path to a file in the file system, etc.
getDisplayName()java.lang.String getDisplayName()
Display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.
java.lang.Class<?> getTestClass()
Class associated with the current test or container.java.lang.reflect.AnnotatedElement getElement()
AnnotatedElement corresponding to the current extension
context.
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 (e.g., when
looking up annotations regardless of concrete element type).
getTestClass()void publishReportEntry(java.util.Map<java.lang.String,java.lang.String> values)
org.junit.gen5.engine.EngineExecutionListener.values - the map of values to be reported for this entrydefault ExtensionContext.Store getStore()
ExtensionContext.Store with the default ExtensionContext.Namespace.getStore(Namespace)ExtensionContext.Store getStore(ExtensionContext.Namespace namespace)
ExtensionContext.Store for a self constructed ExtensionContext.Namespace.