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.
Store
, Namespace
Modifier and Type | Class and Description |
---|---|
public static class | ExtensionContext.
A |
public static interface | ExtensionContext.
|
Modifier and Type | Method and Description |
---|---|
public Optional | Returns: anOptional containing the value; never null
but potentially emptythe key to look up; never key)null or blankGet the configuration parameter stored under the specified |
public <T> Optional | Returns: anOptional containing the value; never null
but potentially emptythe key to look up; never key, Function<String, T> null or blankthe transformer to apply in case a value is found;
never transformer)null Get and transform the configuration parameter stored under the specified
|
public String | Returns: the display name of the test or container; nevernull or blankGet the display name for the current test or container. |
public Optional | Returns: anOptional containing the AnnotatedElement ;
never null but potentially emptyGet the |
public ExecutableInvoker | getExecutableInvoker()
Get an |
public Optional | Returns: anOptional containing the exception thrown; never
null but potentially empty if test execution has not (yet)
resulted in an exceptionGet the exception that was thrown during execution of the test or container
associated with this |
public ExecutionMode | Returns: theExecutionMode of the test; never null Get the |
public Optional | Returns: anOptional containing the parent; never null but
potentially emptyGet the parent extension context, if available. |
public default Class | Returns: the test class; nevernull Get the required |
public default Object | Returns: the test instance; nevernull Get the required test instance associated with the current test or container. |
public default TestInstances | Returns: the test instances; nevernull Get the required test instances associated with the current test or container. |
public default Method | Returns: the test method; nevernull Get the required |
public ExtensionContext | Returns: the root extension context; nevernull but potentially
this ExtensionContext Get the root |
public ExtensionContext. | Returns: the store in which to put and get objects for other invocations working in the same namespace; nevernull the namespaceNamespace to get the store for; never null |
public Set | Returns: the set of tags for the test or container; nevernull but
potentially emptyGet the set of all tags for the current test or container. |
public Optional | Returns: anOptional containing the class; never null but
potentially emptyGet the |
public Optional | Returns: anOptional containing the test instance; never
null but potentially emptyGet the test instance associated with the current test or container, if available. |
public Optional | Returns: anOptional containing the test instance Lifecycle ;
never null but potentially emptyGet the |
public Optional | Returns: anOptional containing the test instances; never
null but potentially emptyGet the test instances associated with the current test or container, if available. |
public Optional | Returns: anOptional containing the method; never null but
potentially emptyGet the |
public String | Returns: the unique ID of the test or container; nevernull or blankGet the unique ID of the current test or container. |
public void | publishReportEntry(Map<String, String>
the key-value pairs to be published; never map)null ;
keys and values within entries in the map also must not be
null or blankPublish a map of key-value pairs to be consumed by an
|
public default void | publishReportEntry(String
the key of the published pair; never key, String null or blankthe value of the published pair; never value)null or blankPublish the specified key-value pair to be consumed by an
|
public default void | publishReportEntry(String
the value to be published; never value)null or blankPublish the specified value to be consumed by an
|
getConfigurationParameter | back to summary |
---|---|
public Optional Get the configuration parameter stored under the specified If no such key is present in the
|
getConfigurationParameter | back to summary |
---|---|
public <T> Optional Get and transform the configuration parameter stored under the specified
If no such key is present in the In case the transformer throws an exception, it will be wrapped in a
|
getDisplayName | back to summary |
---|---|
public String getDisplayName() Get the display name for the current test or container. The display name is either a default name or a custom name configured
via For details on default display names consult the Javadoc for
Note that display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.
|
getElement | back to summary |
---|---|
public Optional Get the For example, if the current extension context encapsulates a test
class, test method, test factory method, or test template method, the
annotated element will be the corresponding Favor this method over more specific methods whenever the
|
getExecutableInvoker | back to summary |
---|---|
public ExecutableInvoker getExecutableInvoker() Get an
|
getExecutionException | back to summary |
---|---|
public Optional Get the exception that was thrown during execution of the test or container
associated with this This method is typically used for logging and tracing purposes. If you
wish to actually handle an exception thrown during test execution,
implement the Unlike the exception passed to a Note, however, that this method will never return an exception
swallowed by a |
getExecutionMode | back to summary |
---|---|
public ExecutionMode getExecutionMode() Get the
|
getParent | back to summary |
---|---|
public Optional Get the parent extension context, if available.
|
getRequiredTestClass | back to summary |
---|---|
public default Class Get the required Use this method as an alternative to
|
getRequiredTestInstance | back to summary |
---|---|
public default Object getRequiredTestInstance() Get the required test instance associated with the current test or container. Use this method as an alternative to
|
getRequiredTestInstances | back to summary |
---|---|
public default TestInstances getRequiredTestInstances() Get the required test instances associated with the current test or container. Use this method as an alternative to
|
getRequiredTestMethod | back to summary |
---|---|
public default Method getRequiredTestMethod() Get the required Use this method as an alternative to
|
getRoot | back to summary |
---|---|
public ExtensionContext getRoot() Get the root
|
getStore | back to summary |
---|---|
public ExtensionContext. Get the Use A store is bound to its extension context lifecycle. When an extension
context lifecycle ends it closes its associated store. All stored values
that are instances of
|
getTags | back to summary |
---|---|
public Set Get the set of all tags for the current test or container. Tags may be declared directly on the test element or inherited from an outer context. |
getTestClass | back to summary |
---|---|
public Optional Get the
|
getTestInstance | back to summary |
---|---|
public Optional Get the test instance associated with the current test or container, if available.
|
getTestInstanceLifecycle | back to summary |
---|---|
public Optional Get the
|
getTestInstances | back to summary |
---|---|
public Optional Get the test instances associated with the current test or container, if available. While top-level tests only have a single test instance, nested tests have one additional instance for each enclosing test class.
|
getTestMethod | back to summary |
---|---|
public Optional Get the
|
getUniqueId | back to summary |
---|---|
public String getUniqueId() Get the unique ID of the current test or container.
|
publishReportEntry | back to summary |
---|---|
public void publishReportEntry(Map<String, String> map) Publish a map of key-value pairs to be consumed by an
|
publishReportEntry | back to summary |
---|---|
public default void publishReportEntry(String key, String value) Publish the specified key-value pair to be consumed by an
|
publishReportEntry | back to summary |
---|---|
public default void publishReportEntry(String value) Publish the specified value to be consumed by an
This method delegates to
|
Namespace
is used to provide a scope for data saved by
extensions within a Store
.
Storing data in custom namespaces allows extensions to avoid accidentally mixing data between extensions or across different invocations within the lifecycle of a single extension.
Modifier and Type | Field and Description |
---|---|
public static final ExtensionContext. | GLOBAL
The default, global namespace which allows access to stored data from all extensions. |
private final List |
Modifier and Type | Method and Description |
---|---|
public ExtensionContext. | |
public static ExtensionContext. | |
public boolean | equals(Object
the reference object with which to compare. o)Overrides java. |
public int |
GLOBAL | back to summary |
---|---|
public static final ExtensionContext. The default, global namespace which allows access to stored data from all extensions. |
parts | back to summary |
---|---|
private final List<Object> parts |
Namespace | back to summary |
---|---|
private Namespace(List<Object> parts) |
append | back to summary |
---|---|
public ExtensionContext. Create a new namespace by appending the supplied
|
create | back to summary |
---|---|
public static ExtensionContext. Create a namespace which restricts access to data to all extensions
which use the same sequence of The order of the Internally the |
equals | back to summary |
---|---|
public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. |
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
|
Store
provides methods for extensions to save and retrieve data.
Modifier and Type | Class and Description |
---|---|
public static interface | ExtensionContext.
Classes implementing this interface indicate that they want to |
Modifier and Type | Method and Description |
---|---|
public Object | |
public < the value type V> V | |
public default < the key and value type V> V | Returns: the object; nevernull the type of object to retrieve; never type)null Get the object of type |
public < the key type K, the value type V> Object | Returns: the value; potentiallynull the key; never key, Function<K, V> null the function called with the supplied defaultCreator)key
to create a new value; never null but may return null Get the value that is stored under the supplied |
public < the key type K, the value type V> V | Returns: the value; potentiallynull the key; never key, Function<K, V> null the function called with the supplied defaultCreator, Class<V> key
to create a new value; never null but may return null the required type of the value; never requiredType)null Get the value of the specified required type that is stored under the
supplied |
public default < the value type V> V | Returns: the value; potentiallynull the key; never key, Class<V> null the required type of the value; never requiredType, V null the default value defaultValue)Get the value of the specified required type that is stored under
the supplied |
public void | |
public Object | |
public < the value type V> V |
get | back to summary |
---|---|
public Object get(Object key) Get the value that is stored under the supplied If no value is stored in the current For greater type safety, consider using
|
get | back to summary |
---|---|
public <V> V get(Object key, Class<V> requiredType) Get the value of the specified required type that is stored under
the supplied If no value is stored in the current
|
getOrComputeIfAbsent | back to summary |
---|---|
public default <V> V getOrComputeIfAbsent(Class<V> type) Get the object of type This method is a shortcut for the following, where X x = store.getOrComputeIfAbsent(X.class, key -> new X(), X.class); // Equivalent to: // X x = store.getOrComputeIfAbsent(X.class); See If
|
getOrComputeIfAbsent | back to summary |
---|---|
public <K, V> Object getOrComputeIfAbsent(K key, Function<K, V> defaultCreator) Get the value that is stored under the supplied If no value is stored in the current For greater type safety, consider using
If the created value is an instance of
|
getOrComputeIfAbsent | back to summary |
---|---|
public <K, V> V getOrComputeIfAbsent(K key, Function<K, V> defaultCreator, Class<V> requiredType) Get the value of the specified required type that is stored under the
supplied If no value is stored in the current If
|
getOrDefault | back to summary |
---|---|
public default <V> V getOrDefault(Object key, Class<V> requiredType, V defaultValue) Get the value of the specified required type that is stored under
the supplied If no value is stored in the current
|
put | back to summary |
---|---|
public void put(Object key, Object value) Store a A stored If the
|
remove | back to summary |
---|---|
public Object remove(Object key) Remove the value that was previously stored under the supplied The value will only be removed in the current For greater type safety, consider using
|
remove | back to summary |
---|---|
public <V> V remove(Object key, Class<V> requiredType) Remove the value of the specified required type that was previously stored
under the supplied The value will only be removed in the current
|
close
some underlying resource or resources when the enclosing Store
is closed.
Note that the CloseableResource
API is only honored for
objects stored within an extension context Store
.
The resources stored in a Store
are closed in the
inverse order they were added in.
Modifier and Type | Method and Description |
---|---|
public void |
close | back to summary |
---|---|
public void close() throws Throwable Close underlying resources.
|